diff --git a/cake/libs/cache/memcache.php b/cake/libs/cache/memcache.php index 32df6f0ab..c9616ea7a 100644 --- a/cake/libs/cache/memcache.php +++ b/cake/libs/cache/memcache.php @@ -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); } diff --git a/cake/tests/cases/libs/cache/memcache.test.php b/cake/tests/cases/libs/cache/memcache.test.php index 9c566c1a1..8f7715c3c 100644 --- a/cake/tests/cases/libs/cache/memcache.test.php +++ b/cake/tests/cases/libs/cache/memcache.test.php @@ -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); } }