mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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:
parent
d5ffdc288d
commit
c3d5c3fd00
4 changed files with 21 additions and 4 deletions
|
@ -296,7 +296,7 @@ class Cache {
|
||||||
}
|
}
|
||||||
$key = $self->_engines[$config]->key($key);
|
$key = $self->_engines[$config]->key($key);
|
||||||
|
|
||||||
if (!$key || is_resource($value) || $settings['duration'] < 1) {
|
if (!$key || is_resource($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
cake/libs/cache/file.php
vendored
1
cake/libs/cache/file.php
vendored
|
@ -265,6 +265,7 @@ class FileEngine extends CacheEngine {
|
||||||
if ($this->_init && !is_writable($this->settings['path'])) {
|
if ($this->_init && !is_writable($this->settings['path'])) {
|
||||||
$this->_init = false;
|
$this->_init = false;
|
||||||
trigger_error(sprintf(__('%s is not writable', true), $this->settings['path']), E_USER_WARNING);
|
trigger_error(sprintf(__('%s is not writable', true), $this->settings['path']), E_USER_WARNING);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,14 +120,15 @@ class CacheTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testInvaidConfig() {
|
function testInvaidConfig() {
|
||||||
$this->expectError();
|
$this->expectError();
|
||||||
Cache::config('Invalid', array(
|
Cache::config('invalid', array(
|
||||||
'engine' => 'File',
|
'engine' => 'File',
|
||||||
'duration' => '+1 year',
|
'duration' => '+1 year',
|
||||||
'prefix' => 'testing_invalid_',
|
'prefix' => 'testing_invalid_',
|
||||||
'path' => 'data/',
|
'path' => 'data/',
|
||||||
'serialize' => true
|
'serialize' => true,
|
||||||
|
'random' => 'wii'
|
||||||
));
|
));
|
||||||
$read = Cache::read('Test', 'Invalid');
|
$read = Cache::read('Test', 'invalid');
|
||||||
$this->assertEqual($read, null);
|
$this->assertEqual($read, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
cake/tests/cases/libs/cache/memcache.test.php
vendored
15
cake/tests/cases/libs/cache/memcache.test.php
vendored
|
@ -303,4 +303,19 @@ class MemcacheEngineTest extends CakeTestCase {
|
||||||
Cache::delete('short_duration_test', 'short_memcache');
|
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!');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue