diff --git a/core/lib/Drupal/Core/Cache/CacheCollector.php b/core/lib/Drupal/Core/Cache/CacheCollector.php index b49b5a4..9c4a74f 100644 --- a/core/lib/Drupal/Core/Cache/CacheCollector.php +++ b/core/lib/Drupal/Core/Cache/CacheCollector.php @@ -8,25 +8,23 @@ namespace Drupal\Core\Cache; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\DestructableInterface; use Drupal\Core\Lock\LockBackendInterface; /** * Default implementation for CacheCollectorInterface. * * By default, the class accounts for caches where calling functions might - * request keys that won't exist even after a cache rebuild. This - * prevents situations where a cache rebuild would be triggered over and over - * due to a 'missing' item. These cases are stored internally as a value of - * NULL. This means that the CacheCollector::get() method must be overridden if - * caching data where the values can legitimately be NULL, and where + * request keys that won't exist even after a cache rebuild. This prevents + * situations where a cache rebuild would be triggered over and over due to a + * 'missing' item. These cases are stored internally as a value of NULL. This + * means that the CacheCollector::get() method must be overridden if caching + * data where the values can legitimately be NULL, and where * CacheCollector->has() needs to correctly return (equivalent to * array_key_exists() vs. isset()). This should not be necessary in the majority * of cases. - * - * Classes extending this class must override at least the - * CacheCollector::resolveCacheMiss() method to have a working implementation. */ -abstract class CacheCollector implements CacheCollectorInterface { +abstract class CacheCollector implements CacheCollectorInterface, DestructableInterface { /** * A cid to pass to cache()->set() and cache()->get(). @@ -148,12 +146,12 @@ public function delete($key) { /** * Flags an offset value to be written to the persistent cache. * - * @param $key + * @param string $key * The key that was request. - * @param $persist - * Optional boolean to specify whether the offset should be persisted or - * not, defaults to TRUE. When called with $persist = FALSE the offset will - * be unflagged so that it will not written at the end of the request. + * @param bool $persist + * (ptional) Whether the offset should be persisted or not, defaults to + * TRUE. When called with $persist = FALSE the offset will be unflagged so + * that it will not written at the end of the request. */ protected function persist($key, $persist = TRUE) { $this->keysToPersist[$key] = $persist; @@ -166,7 +164,7 @@ protected function persist($key, $persist = TRUE) { * miss. This method allows classes using this implementatio to look up the * actual value and allow it to be cached. * - * @param $key + * @param sring $key * The offset that was requested. * * @return @@ -177,10 +175,9 @@ protected function persist($key, $persist = TRUE) { /** * Writes a value to the persistent cache immediately. * - * @param $data - * The data to write to the persistent cache. - * @param $lock - * Whether to acquire a lock before writing to cache. + * @param bool $lock + * (optional) Whether to acquire a lock before writing to cache. Defaults to + * TRUE. */ protected function updateCache($lock = TRUE) { $data = array(); @@ -209,6 +206,9 @@ protected function updateCache($lock = TRUE) { $this->lock->release($lock_name); } } + + $this->keysToPersist = array(); + $this->keysToRemove = array(); } /** @@ -226,4 +226,5 @@ public function reset() { $this->keysToPersist = array(); $this->keysToRemove = array(); } + } diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueCacheDecorator.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueCacheDecorator.php index c177bed..dcbd7ff 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueCacheDecorator.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueCacheDecorator.php @@ -31,14 +31,14 @@ class KeyValueCacheDecorator extends CacheCollector implements KeyValueStoreInte * The cache backend to store the cache in. * @param \Drupal\Core\Lock\LockBackendInterface $lock * The lock implementation to use when writing a changed cache storage. - * @param \Drupal\Core\KeyValueStore\KeyValueFactory $keyValueFactory + * @param \Drupal\Core\KeyValueStore\KeyValueFactory $key_value_factory * The key value factory to get the key value storage from. * @param string $collection * Name of the key value storage collection, also used as the cache id. */ - public function __construct(CacheBackendInterface $cache, LockBackendInterface $lock, KeyValueFactory $keyValueFactory, $collection) { + public function __construct(CacheBackendInterface $cache, LockBackendInterface $lock, KeyValueFactory $key_value_factory, $collection) { parent::__construct($collection, $cache, $lock); - $this->keyValueStore = $keyValueFactory->get($collection); + $this->keyValueStore = $key_value_factory->get($collection); } /** @@ -62,7 +62,7 @@ public function delete($key) { } /** - * Overrides \Drupal\Core\Cache\CacheCollector::deleteMultiple(). + * Implements KeyValueStoreInterface::deleteMultiple(). */ public function deleteMultiple(array $keys) { foreach ($keys as $key) { diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/CacheDecoratorTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/CacheDecoratorTest.php index fa56f24..a18b102 100644 --- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/CacheDecoratorTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/CacheDecoratorTest.php @@ -37,7 +37,7 @@ protected function setUp() { ->register('keyvalue.memory', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory'); global $conf; $conf['keyvalue_default'] = 'keyvalue.memory'; - $this->cache = $cache = new MemoryBackend('bin'); + $this->cache = new MemoryBackend('bin'); } /**