Skip to content
Permalink
Browse files

Fixing issues with ApcEngine and duration = 0 (forever)

values.  Fixes #1795
  • Loading branch information...
markstory committed Jul 2, 2011
1 parent 2470096 commit ee1634819ad44d3a82cfb409bc21372af6bd6394
Showing with 20 additions and 2 deletions.
  1. +6 −2 cake/libs/cache/apc.php
  2. +14 −0 cake/tests/cases/libs/cache/apc.test.php
@@ -53,7 +53,11 @@ function init($settings = array()) {
* @access public
*/
function write($key, &$value, $duration) {
$expires = time() + $duration;
if ($duration == 0) {
$expires = 0;
} else {
$expires = time() + $duration;
}
apc_store($key.'_expires', $expires, $duration);
return apc_store($key, $value, $duration);
}
@@ -68,7 +72,7 @@ function write($key, &$value, $duration) {
function read($key) {
$time = time();
$cachetime = intval(apc_fetch($key.'_expires'));
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
if ($cachetime !== 0 && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
return false;
}
return apc_fetch($key);
@@ -91,6 +91,20 @@ function testReadAndWriteCache() {
Cache::delete('test');
}
/**
* Writing cache entries with duration = 0 (forever) should work.
*
* @return void
*/
function testReadWriteDurationZero() {
Cache::config('apc', array('engine' => 'Apc', 'duration' => 0, 'prefix' => 'cake_'));
Cache::write('zero', 'Should save', 'apc');
sleep(1);
$result = Cache::read('zero', 'apc');
$this->assertEqual('Should save', $result);
}
/**
* testExpiry method
*

0 comments on commit ee16348

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.