Skip to content

Commit c3d5c3f

Browse files
committed
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
1 parent d5ffdc2 commit c3d5c3f

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

cake/libs/cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ function write($key, $value, $config = null) {
296296
}
297297
$key = $self->_engines[$config]->key($key);
298298

299-
if (!$key || is_resource($value) || $settings['duration'] < 1) {
299+
if (!$key || is_resource($value)) {
300300
return false;
301301
}
302302

cake/libs/cache/file.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ function __active() {
265265
if ($this->_init && !is_writable($this->settings['path'])) {
266266
$this->_init = false;
267267
trigger_error(sprintf(__('%s is not writable', true), $this->settings['path']), E_USER_WARNING);
268+
return false;
268269
}
269270
return true;
270271
}

cake/tests/cases/libs/cache.test.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,15 @@ function testConfigWithLibAndPluginEngines() {
120120
*/
121121
function testInvaidConfig() {
122122
$this->expectError();
123-
Cache::config('Invalid', array(
123+
Cache::config('invalid', array(
124124
'engine' => 'File',
125125
'duration' => '+1 year',
126126
'prefix' => 'testing_invalid_',
127127
'path' => 'data/',
128-
'serialize' => true
128+
'serialize' => true,
129+
'random' => 'wii'
129130
));
130-
$read = Cache::read('Test', 'Invalid');
131+
$read = Cache::read('Test', 'invalid');
131132
$this->assertEqual($read, null);
132133
}
133134

cake/tests/cases/libs/cache/memcache.test.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,19 @@ function testConfigurationConflict() {
303303
Cache::delete('short_duration_test', 'short_memcache');
304304
}
305305

306+
/**
307+
* test that a 0 duration can succesfully write.
308+
*
309+
* @return void
310+
*/
311+
function testZeroDuration() {
312+
Cache::config('memcache', array('duration' => 0));
313+
$result = Cache::write('test_key', 'written!', 'memcache');
314+
315+
$this->assertTrue($result, 'Could not write with duration 0');
316+
$result = Cache::read('test_key', 'memcache');
317+
$this->assertEqual($result, 'written!');
318+
319+
}
320+
306321
}

0 commit comments

Comments
 (0)