updating cache engines so key will expire when duration is changed, updated datasource and configure to for new settings, closes #5083

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7364 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-07-26 20:00:20 +00:00
parent 4451c02b1c
commit caa7bb6218
11 changed files with 80 additions and 45 deletions

View file

@ -57,6 +57,8 @@ class ApcEngine extends CacheEngine {
* @access public
*/
function write($key, &$value, $duration) {
$expires = time() + $duration;
apc_store($key.'_expires', $expires, $duration);
return apc_store($key, $value, $duration);
}
/**
@ -67,6 +69,11 @@ class ApcEngine extends CacheEngine {
* @access public
*/
function read($key) {
$time = time();
$cachetime = intval(apc_fetch($key.'_expires'));
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
return false;
}
return apc_fetch($key);
}
/**

View file

@ -128,9 +128,6 @@ class FileEngine extends CacheEngine {
return false;
}
if ($duration == null) {
$duration = $this->settings['duration'];
}
$lineBreak = "\n";
if ($this->settings['isWindows']) {
@ -168,9 +165,10 @@ class FileEngine extends CacheEngine {
if ($this->settings['lock']) {
$this->__File->lock = true;
}
$cachetime = $this->__File->read(11);
$time = time();
$cachetime = intval($this->__File->read(11));
if ($cachetime !== false && intval($cachetime) < time()) {
if ($cachetime !== false && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
$this->__File->close();
$this->__File->delete();
return false;

View file

@ -100,6 +100,8 @@ class MemcacheEngine extends CacheEngine {
* @access public
*/
function write($key, &$value, $duration) {
$expires = time() + $duration;
$this->__Memcache->set($key.'_expires', $expires, $this->settings['compress'], $duration);
return $this->__Memcache->set($key, $value, $this->settings['compress'], $duration);
}
/**
@ -110,6 +112,11 @@ class MemcacheEngine extends CacheEngine {
* @access public
*/
function read($key) {
$time = time();
$cachetime = intval($this->__Memcache->get($key.'_expires'));
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
return false;
}
return $this->__Memcache->get($key);
}
/**

View file

@ -69,6 +69,8 @@ class XcacheEngine extends CacheEngine {
* @access public
*/
function write($key, &$value, $duration) {
$expires = time() + $duration;
xcache_set($key.'_expires', $expires, $duration);
return xcache_set($key, $value, $duration);
}
/**
@ -80,6 +82,11 @@ class XcacheEngine extends CacheEngine {
*/
function read($key) {
if (xcache_isset($key)) {
$time = time();
$cachetime = intval(xcache_get($key.'_expires'));
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
return false;
}
return xcache_get($key);
}
return false;