diff --git a/cake/libs/cache.php b/cake/libs/cache.php index 01acb220d..3164b5ec9 100644 --- a/cake/libs/cache.php +++ b/cake/libs/cache.php @@ -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; } diff --git a/cake/libs/cache/file.php b/cake/libs/cache/file.php index 3494c62ce..55a678100 100644 --- a/cake/libs/cache/file.php +++ b/cake/libs/cache/file.php @@ -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; } diff --git a/cake/tests/cases/libs/cache.test.php b/cake/tests/cases/libs/cache.test.php index a5ca8af73..d6f98082c 100644 --- a/cake/tests/cases/libs/cache.test.php +++ b/cake/tests/cases/libs/cache.test.php @@ -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); } diff --git a/cake/tests/cases/libs/cache/memcache.test.php b/cake/tests/cases/libs/cache/memcache.test.php index 907281175..8eca01af6 100644 --- a/cake/tests/cases/libs/cache/memcache.test.php +++ b/cake/tests/cases/libs/cache/memcache.test.php @@ -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!'); + + } + }