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:
36
cache/CacheKey.php
vendored
36
cache/CacheKey.php
vendored
@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user