1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68:
<?php
namespace Apptus\Util\Cache;
class PrefixStateCache implements StateCache {
private $prefix;
private $stateCache;
public function __construct($prefix, StateCache $stateCache) {
$this->prefix = (string) $prefix;
$this->stateCache = $stateCache;
}
public function add($key, $value, $expire) {
return $this->stateCache->add($this->prefix . $key, $value, $expire);
}
public function delete($key) {
return $this->stateCache->delete($this->prefix . $key);
}
public function get($key) {
return $this->stateCache->get($this->prefix . $key);
}
public function getMulti($keys) {
$prefixedKeys = array ();
foreach ($keys as $key) {
$prefixedKeys[] = $this->prefix . $key;
}
$prefixedResult = $this->stateCache->getMulti($prefixedKeys);
$prefixLength = strlen($this->prefix);
$result = array ();
foreach ($prefixedResult as $prefixedKey => $value) {
$result[substr($prefixedKey, $prefixLength)] = $value;
}
return $result;
}
public function replace($key, $value, $expire) {
return $this->stateCache->replace($this->prefix . $key, $value, $expire);
}
public function set($key, $value, $expire) {
return $this->stateCache->set($this->prefix . $key, $value, $expire);
}
public function setMulti($items, $expire) {
$prefixedItems = array ();
foreach ($items as $key => $value) {
$prefixedItems[$this->prefix . $key] = $value;
}
return $this->stateCache->setMulti($prefixedItems, $expire);
}
}