Commit 268f6c32 authored by catch's avatar catch

Issue #2581395 by moshe weitzman, kylebrowning, dawehner: Incorrect expiration in APCUBackend

parent 74a50236
......@@ -68,7 +68,7 @@ public function __construct($bin, $site_prefix, CacheTagsChecksumInterface $chec
* @return string
* The APCu key for the cache item ID.
*/
protected function getApcuKey($cid) {
public function getApcuKey($cid) {
return $this->binPrefix . $cid;
}
......@@ -178,14 +178,8 @@ public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANEN
$cache->serialized = 0;
$cache->data = $data;
// apc_store()'s $ttl argument can be omitted but also set to 0 (zero),
// in which case the value will persist until it's removed from the cache or
// until the next cache clear, restart, etc. This is what we want to do
// when $expire equals CacheBackendInterface::CACHE_PERMANENT.
if ($expire === CacheBackendInterface::CACHE_PERMANENT) {
$expire = 0;
}
apc_store($this->getApcuKey($cid), $cache, $expire);
// Expiration is handled by our own prepareItem(), not APCu.
apc_store($this->getApcuKey($cid), $cache);
}
/**
......
......@@ -87,6 +87,15 @@ public function testSetGet() {
return;
}
parent::testSetGet();
// Make sure entries are permanent (i.e. no TTL).
$backend = $this->getCacheBackend($this->getTestBin());
$key = $backend->getApcuKey('TEST8');
foreach (new \APCIterator('user', '/^' . $key . '/') as $item) {
$this->assertEqual(0, $item['ttl']);
$found = TRUE;
}
$this->assertTrue($found);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment