Memcache, refactoring, View helpers, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@124 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
72
cache/CacheKey.php
vendored
Normal file
72
cache/CacheKey.php
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage Cache
|
||||
* @since 2010-03-10
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
|
||||
class CacheKey
|
||||
{
|
||||
|
||||
protected $key;
|
||||
protected $params = '';
|
||||
protected $expire = 0;
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $params
|
||||
* @param iCacheable $cacheable
|
||||
* @return CacheKey
|
||||
*/
|
||||
public function __construct($key, $params = array(), $cacheable)
|
||||
{
|
||||
$this->key = $key;
|
||||
if (!$cacheable instanceof iCacheable) {
|
||||
throw new GeneralException('CacheKey depends on iCacheable instance');
|
||||
}
|
||||
$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;
|
||||
}
|
||||
|
||||
protected function getExpire()
|
||||
{
|
||||
return $this->expire;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $expire
|
||||
*/
|
||||
public function setExpire($expire)
|
||||
{
|
||||
$this->expire = $expire;
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
return $this->cache->get($this->getCacheKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function set($value)
|
||||
{
|
||||
return $this->cache->set($this->getCacheKey(), $value, $this->expire);
|
||||
}
|
||||
|
||||
public function del()
|
||||
{
|
||||
return $this->cache->del($this->getCacheKey());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user