Fixing issue in Cache where duration = 0 would not read/write from cache. 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
This commit is contained in:
mark_story 2010-09-19 12:20:07 -04:00
parent d5ffdc288d
commit c3d5c3fd00
4 changed files with 21 additions and 4 deletions

View file

@ -296,7 +296,7 @@ class Cache {
}
$key = $self->_engines[$config]->key($key);
if (!$key || is_resource($value) || $settings['duration'] < 1) {
if (!$key || is_resource($value)) {
return false;
}

View file

@ -265,6 +265,7 @@ class FileEngine extends CacheEngine {
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;
}

View file

@ -120,14 +120,15 @@ class CacheTest extends CakeTestCase {
*/
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);
}

View file

@ -303,4 +303,19 @@ class MemcacheEngineTest extends CakeTestCase {
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!');
}
}