mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Making memcache cache adapter, set the expiry time of any value greater than 30 days to never expire. This works around the 30 day limitation of the PHP extension. Test case added. Fixes #1451
This commit is contained in:
parent
0f4c90588d
commit
5f612b7833
2 changed files with 27 additions and 3 deletions
6
cake/libs/cache/memcache.php
vendored
6
cake/libs/cache/memcache.php
vendored
|
@ -119,8 +119,7 @@ class MemcacheEngine extends CacheEngine {
|
|||
/**
|
||||
* Write data for key into cache. When using memcache as your cache engine
|
||||
* remember that the Memcache pecl extension does not support cache expiry times greater
|
||||
* than 30 days in the future. If you wish to create cache entries that do not expire, set the duration
|
||||
* to `0` in your cache configuration.
|
||||
* than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param mixed $value Data to be cached
|
||||
|
@ -130,6 +129,9 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @access public
|
||||
*/
|
||||
function write($key, &$value, $duration) {
|
||||
if ($duration > 30 * DAY) {
|
||||
$duration = 0;
|
||||
}
|
||||
return $this->__Memcache->set($key, $value, $this->settings['compress'], $duration);
|
||||
}
|
||||
|
||||
|
|
22
cake/tests/cases/libs/cache/memcache.test.php
vendored
22
cake/tests/cases/libs/cache/memcache.test.php
vendored
|
@ -33,8 +33,14 @@ class TestMemcacheEngine extends MemcacheEngine {
|
|||
function parseServerString($server) {
|
||||
return $this->_parseServerString($server);
|
||||
}
|
||||
|
||||
function setMemcache(&$memcache) {
|
||||
$this->__Memcache = $memcache;
|
||||
}
|
||||
}
|
||||
|
||||
Mock::generate('Memcache', 'MemcacheMockMemcache');
|
||||
|
||||
/**
|
||||
* MemcacheEngineTest class
|
||||
*
|
||||
|
@ -361,7 +367,23 @@ class MemcacheEngineTest extends CakeTestCase {
|
|||
$this->assertTrue($result, 'Could not write with duration 0');
|
||||
$result = Cache::read('test_key', 'memcache');
|
||||
$this->assertEqual($result, 'written!');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that durations greater than 30 days never expire
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testLongDurationEqualToZero() {
|
||||
$memcache =& new TestMemcacheEngine();
|
||||
$memcache->settings['compress'] = false;
|
||||
|
||||
$mock = new MemcacheMockMemcache();
|
||||
$memcache->setMemcache($mock);
|
||||
$mock->expectAt(0, 'set', array('key', 'value', false, 0));
|
||||
|
||||
$value = 'value';
|
||||
$memcache->write('key', $value, 50 * DAY);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue