Skip to content

Commit

Permalink
Fixing issue in Cache where duration = 0 would not read/write from ca…
Browse files Browse the repository at this point in the history
…che. This prevented the creation of non expiring cache entries in APC and memcache.

Adding a return false to FileEngine as it was omitted in the past.
Fixes #1120
  • Loading branch information
markstory committed Sep 19, 2010
1 parent d5ffdc2 commit c3d5c3f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cake/libs/cache.php
Expand Up @@ -296,7 +296,7 @@ function write($key, $value, $config = null) {
}
$key = $self->_engines[$config]->key($key);

if (!$key || is_resource($value) || $settings['duration'] < 1) {
if (!$key || is_resource($value)) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions cake/libs/cache/file.php
Expand Up @@ -265,6 +265,7 @@ function __active() {
if ($this->_init && !is_writable($this->settings['path'])) {
$this->_init = false;
trigger_error(sprintf(__('%s is not writable', true), $this->settings['path']), E_USER_WARNING);
return false;
}
return true;
}
Expand Down
7 changes: 4 additions & 3 deletions cake/tests/cases/libs/cache.test.php
Expand Up @@ -120,14 +120,15 @@ function testConfigWithLibAndPluginEngines() {
*/
function testInvaidConfig() {
$this->expectError();
Cache::config('Invalid', array(
Cache::config('invalid', array(
'engine' => 'File',
'duration' => '+1 year',
'prefix' => 'testing_invalid_',
'path' => 'data/',
'serialize' => true
'serialize' => true,
'random' => 'wii'
));
$read = Cache::read('Test', 'Invalid');
$read = Cache::read('Test', 'invalid');
$this->assertEqual($read, null);
}

Expand Down
15 changes: 15 additions & 0 deletions cake/tests/cases/libs/cache/memcache.test.php
Expand Up @@ -303,4 +303,19 @@ function testConfigurationConflict() {
Cache::delete('short_duration_test', 'short_memcache');
}

/**
* test that a 0 duration can succesfully write.
*
* @return void
*/
function testZeroDuration() {
Cache::config('memcache', array('duration' => 0));
$result = Cache::write('test_key', 'written!', 'memcache');

$this->assertTrue($result, 'Could not write with duration 0');
$result = Cache::read('test_key', 'memcache');
$this->assertEqual($result, 'written!');

}

}

0 comments on commit c3d5c3f

Please sign in to comment.