Files
majestic/Cache/CacheKey.php

74 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage Cache
* @since 2010-03-10
*/
class CacheKey
{
/**
2012-11-19 18:40:04 +04:00
* @var Cache
*/
protected $cacher;
2011-10-13 14:55:06 +04:00
/**
* @var CacheKey
*/
protected $key;
2011-10-13 14:55:06 +04:00
protected $expire = 0;
/**
* @param Cacher $cacher
* @param string $key
* @param mixed $params
* @param int $expire
* @return CacheKey
*/
public function __construct($cacher, $key, $params = array(), $expire = 0)
{
2011-10-13 14:55:06 +04:00
$this->cacher = $cacher;
$this->key = $key;
if ($params) {
$params = (is_array($params)) ? implode('|', $params) : $params;
2011-10-13 14:55:06 +04:00
$this->key = $key . '_' . $params;
}
$this->expire = $expire;
}
protected function getExpire()
{
return $this->expire;
}
/**
* @param int $expire
*/
public function setExpire($expire)
{
$this->expire = $expire;
}
public function get()
{
return $this->cacher->get($this->key);
}
/**
* @param mixed $value
2012-11-19 18:40:04 +04:00
* @return bool
*/
public function set($value)
{
return $this->cacher->set($this->key, $value, $this->expire);
}
public function del()
{
return $this->cacher->del($this->key);
}
}