rhymix/classes/cache/CacheApc.class.php
ngleader f07cc09e4f #18885380 add Cache Handler
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7450 201d5d3c-b55e-5fd7-737f-ddc643e51545
2010-05-12 08:34:23 +00:00

70 lines
1.3 KiB
PHP

<?php
class CacheApc extends CacheBase {
var $valid_time = 3600;
function getInstance(){
if(!$GLOBALS['__CacheApc__']) {
$GLOBALS['__CacheApc__'] = new CacheApc();
}
return $GLOBALS['__CacheApc__'];
}
function CacheApc(){
}
function isSupport(){
return apc_store('xe', 'xe', 1);
}
function put($key, $buff, $valid_time = 0){
if($valid_time == 0) $valid_time = $this->valid_time;
return apc_store(md5(_XE_PATH_.$key), array(time(), $buff), $valid_time);
}
function isValid($key, $modified_time = 0)
{
$key = md5(_XE_PATH_.$key);
$obj = apc_fetch($key, $success);
if(!$success || !is_array($obj)) return false;
unset($obj[1]);
if($modified_time > 0 && $modified_time > $obj[0])
{
$this->delete($_key);
return false;
}
return true;
}
function get($key, $modified_time = 0)
{
$key = md5(_XE_PATH_.$key);
$obj = apc_fetch($key, $success);
if(!$success || !is_array($obj)) return false;
if($modified_time > 0 && $modified_time > $obj[0])
{
$this->_delete($key);
return false;
}
return $obj[1];
}
function _delete($_key)
{
$this->put($_key,null,1);
}
function delete($key)
{
$this->_delete(md5(_XE_PATH_.$key));
}
function truncate()
{
apc_clear_cache('user');
}
}
?>