Redis implementation, #16

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@149 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
pzinovkin
2010-07-19 15:06:01 +00:00
parent 70ccc8bc26
commit 8a6f6097bf
8 changed files with 185 additions and 195 deletions

36
cache/CacheKey.php vendored
View File

@ -12,31 +12,33 @@
class CacheKey
{
/**
* @var Cacher
*/
protected $cacher;
/**
* @var CacheKey
*/
protected $key;
protected $params = '';
protected $expire = 0;
/**
* @param Cacher $cacher
* @param string $key
* @param mixed $params
* @param iCacheable $cacheable
* @param int $expire
* @return CacheKey
*/
public function __construct($key, $params = array(), $cacheable)
public function __construct($cacher, $key, $params = array(), $expire = 0)
{
$this->cacher = $cacher;
$this->key = $key;
if (!$cacheable instanceof iCacheable) {
throw new GeneralException('CacheKey depends on iCacheable instance');
if ($params) {
$params = (is_array($params)) ? implode('|', $params) : $params;
$this->key = $key . '_' . $params;
}
$this->cache = $cacheable->getCache();
$this->expire = $cacheable->getKeyExpire($this->key);
$this->params = (is_array($params)) ? implode('|', $params) : $params;
}
protected function getCacheKey()
{
$params = ($this->params) ? ('_' . $this->params) : '';
return $this->key . $params;
$this->expire = $expire;
}
protected function getExpire()
@ -54,7 +56,7 @@ class CacheKey
public function get()
{
return $this->cache->get($this->getCacheKey());
return $this->cacher->get($this->key);
}
/**
@ -62,11 +64,11 @@ class CacheKey
*/
public function set($value)
{
return $this->cache->set($this->getCacheKey(), $value, $this->expire);
return $this->cacher->set($this->key, $value, $this->expire);
}
public function del()
{
return $this->cache->del($this->getCacheKey());
return $this->cacher->del($this->key);
}
}