diff --git a/core/lib/Drupal/Core/Cache/ApcuBackend.php b/core/lib/Drupal/Core/Cache/ApcuBackend.php index 1e48a5c..0ceafc8 100644 --- a/core/lib/Drupal/Core/Cache/ApcuBackend.php +++ b/core/lib/Drupal/Core/Cache/ApcuBackend.php @@ -178,17 +178,10 @@ 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) { - $ttl = 0; - } - else { - $ttl = max(1, $expire - REQUEST_TIME); - } - apc_store($this->getApcuKey($cid), $cache, $ttl); + // Don't set a time-to-live (ttl) on the APC cache since this can be + // configured by the user in their php.ini. The default ttl is 0 which means + // that items are only removed when the cache is cleared. + apc_store($this->getApcuKey($cid), $cache); } /** @@ -218,21 +211,25 @@ public function deleteMultiple(array $cids) { * {@inheritdoc} */ public function deleteAll() { - apc_delete($this->getAll()); + $this->removeBin(); } /** * {@inheritdoc} */ public function garbageCollection() { - // APC performs garbage collection automatically. + foreach ($this->getAll() as $data) { + if ($data['value']->expire !== Cache::PERMANENT && $data['value']->expire < REQUEST_TIME) { + apc_delete($data['key']); + } + } } /** * {@inheritdoc} */ public function removeBin() { - apc_delete(new \APCIterator('user', '/^' . preg_quote($this->binPrefix, '/') . '/')); + apc_delete($this->getAll()); } /** @@ -250,7 +247,7 @@ public function invalidateMultiple(array $cids) { if ($result) { foreach ($result as $key => $cache) { $cache->expire = REQUEST_TIME - 1; - apc_store($key, $cache, 1); + apc_store($key, $cache); } } } @@ -261,7 +258,7 @@ public function invalidateMultiple(array $cids) { public function invalidateAll() { foreach ($this->getAll() as $data) { $data['value']->expire = REQUEST_TIME - 1; - apc_store($data['key'], $data['value'], 1); + apc_store($data['key'], $data['value']); } }