From c3d5c3fd009076a66f8db1519aadcdfbe1457f06 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 19 Sep 2010 12:20:07 -0400 Subject: [PATCH] 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 --- cake/libs/cache.php | 2 +- cake/libs/cache/file.php | 1 + cake/tests/cases/libs/cache.test.php | 7 ++++--- cake/tests/cases/libs/cache/memcache.test.php | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) 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!'); + + } + }