mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-04-15 10:57:24 +03:00
APC cache improvement
- add cache key prefix - use success param at fetch
This commit is contained in:
parent
c0c58a2a85
commit
bf327cdb24
@ -20,7 +20,7 @@ namespace Handlebars\Cache;
|
||||
use Handlebars\Cache;
|
||||
|
||||
/**
|
||||
* A dummy array cache
|
||||
* A APC cache
|
||||
*
|
||||
* @category Xamin
|
||||
* @package Handlebars
|
||||
@ -34,6 +34,21 @@ use Handlebars\Cache;
|
||||
class APC implements Cache
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_prefix;
|
||||
|
||||
/**
|
||||
* Construct the APC cache.
|
||||
*
|
||||
* @param string|null $prefix optional key prefix, defaults to null
|
||||
*/
|
||||
public function __construct( $prefix = null )
|
||||
{
|
||||
$this->_prefix = (string)$prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache for $name if exist.
|
||||
*
|
||||
@ -43,10 +58,11 @@ class APC implements Cache
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
if (apc_exists($name)) {
|
||||
return apc_fetch($name);
|
||||
}
|
||||
return false;
|
||||
$success = null;
|
||||
$result = apc_fetch($this->_getKey($name), $success);
|
||||
|
||||
return $success ? $result : false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +75,7 @@ class APC implements Cache
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
apc_store($name, $value);
|
||||
apc_store($this->_getKey($name), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +87,19 @@ class APC implements Cache
|
||||
*/
|
||||
public function remove($name)
|
||||
{
|
||||
apc_delete($name);
|
||||
apc_delete($this->_getKey($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the full cache key for a given cache item's
|
||||
*
|
||||
* @param string $name Name of the cache item
|
||||
*
|
||||
* @return string full cache key of cached item
|
||||
*/
|
||||
private function _getKey($name)
|
||||
{
|
||||
return $this->_prefix . ':' . $name;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user