diff -u b/core/lib/Drupal/Core/Config/CachedStorage.php b/core/lib/Drupal/Core/Config/CachedStorage.php --- b/core/lib/Drupal/Core/Config/CachedStorage.php +++ b/core/lib/Drupal/Core/Config/CachedStorage.php @@ -9,7 +9,6 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\Cache\CacheFactoryInterface; /** * Defines the cached storage. @@ -68,7 +67,7 @@ * Implements Drupal\Core\Config\StorageInterface::read(). */ public function read($name) { - $cache_key = $this->createCacheKey($name); + $cache_key = $this->getCacheKey($name); if ($cache = $this->cache->get($cache_key)) { // The cache contains either the cached configuration data or FALSE // if the configuration file does not exist. @@ -86,17 +85,16 @@ */ public function readMultiple(array $names) { $data_to_return = array(); - // The names array is passed by reference and will only contain the names of - // config object not found after the method call. - // @see \Drupal\Core\Cache\CacheBackendInterface::getMultiple() - $cache_keys_map = $this->createCacheKeys($names); + + $cache_keys_map = $this->getCacheKeys($names); $cache_keys = array_values($cache_keys_map); $cached_list = $this->cache->getMultiple($cache_keys); if (!empty($cache_keys)) { - // Whilst the keys of $cache_keys should be the configuration names that - // would for implementation details on CacheBackendInterface::getMultiple() - // that we should not trust. + // $cache_keys_map contains the full $name => $cache_key map, while + // $cache_keys contains just the $cache_key values that weren't found in + // the cache. + // @see \Drupal\Core\Cache\CacheBackendInterface::getMultiple() $names_to_get = array_keys(array_intersect($cache_keys_map, $cache_keys)); $list = $this->storage->readMultiple($names_to_get); // Cache configuration objects that were loaded from the storage, cache @@ -104,16 +102,18 @@ $items = array(); foreach ($names_to_get as $name) { $data = isset($list[$name]) ? $list[$name] : FALSE; + $data_to_return[$name] = $data; $items[$cache_keys_map[$name]] = array('data' => $data); - $data_to_return[$cache_keys_map[$name]] = $data; } $this->cache->setMultiple($items); } // Add the configuration objects from the cache to the list. + $cache_keys_inverse_map = array_flip($cache_keys_map); foreach ($cached_list as $cache_key => $cache) { - $data_to_return[$cache_key] = $cache->data; + $name = $cache_keys_inverse_map[$cache_key]; + $data_to_return[$name] = $cache->data; } // Ensure that only existing configuration objects are returned, filter out @@ -128,7 +128,7 @@ if ($this->storage->write($name, $data)) { // While not all written data is read back, setting the cache instead of // just deleting it avoids cache rebuild stampedes. - $this->cache->set($this->createCacheKey($name), $data); + $this->cache->set($this->getCacheKey($name), $data); Cache::deleteTags(array($this::FIND_BY_PREFIX_CACHE_TAG => TRUE)); $this->findByPrefixCache = array(); return TRUE; @@ -143,7 +143,7 @@ // If the cache was the first to be deleted, another process might start // rebuilding the cache before the storage is gone. if ($this->storage->delete($name)) { - $this->cache->delete($this->createCacheKey($name)); + $this->cache->delete($this->getCacheKey($name)); Cache::deleteTags(array($this::FIND_BY_PREFIX_CACHE_TAG => TRUE)); $this->findByPrefixCache = array(); return TRUE; @@ -158,8 +158,8 @@ // If the cache was the first to be deleted, another process might start // rebuilding the cache before the storage is renamed. if ($this->storage->rename($name, $new_name)) { - $this->cache->delete($this->createCacheKey($name)); - $this->cache->delete($this->createCacheKey($new_name)); + $this->cache->delete($this->getCacheKey($name)); + $this->cache->delete($this->getCacheKey($new_name)); Cache::deleteTags(array($this::FIND_BY_PREFIX_CACHE_TAG => TRUE)); $this->findByPrefixCache = array(); return TRUE; @@ -209,7 +209,7 @@ * An array containing matching configuration object names. */ protected function findByPrefix($prefix) { - $cache_key = $this->createCacheKey($prefix); + $cache_key = $this->getCacheKey($prefix); if (!isset($this->findByPrefixCache[$cache_key])) { // The : character is not allowed in config file names, so this can not // conflict. @@ -237,7 +237,7 @@ // rebuilding the cache before the storage is renamed. $names = $this->storage->listAll($prefix); if ($this->storage->deleteAll($prefix)) { - $this->cache->deleteMultiple($this->createCacheKeys($names)); + $this->cache->deleteMultiple($this->getCacheKeys($names)); return TRUE; } return FALSE; @@ -256,7 +256,7 @@ public function createCollection($collection) { return new static( $this->storage->createCollection($collection), - $this->cacheFactory + $this->cache ); } @@ -275,7 +275,7 @@ } /** - * Creates a cache key for a configuration name using the collection. + * Returns a cache key for a configuration name using the collection. * * @param string $name * The configuration name. @@ -283,12 +283,12 @@ * @return string * The cache key for the configuration name. */ - protected function createCacheKey($name) { + protected function getCacheKey($name) { return $this->getCollectionPrefix() . $name; } /** - * Creates a cache key map for an array of configuration names. + * Returns a cache key map for an array of configuration names. * * @param array $names * The configuration names. @@ -296,7 +296,7 @@ * @return array * An array of cache keys keyed by configuration names. */ - protected function createCacheKeys(array $names) { + protected function getCacheKeys(array $names) { $prefix = $this->getCollectionPrefix(); $cache_keys = array_map(function($name) use ($prefix) { return $prefix . $name; @@ -305,6 +305,12 @@ return array_combine($names, $cache_keys); } + /** + * Returns a cache ID prefix to use for the collection. + * + * @return string + * The cache ID prefix. + */ protected function getCollectionPrefix() { $collection = $this->storage->getCollectionName(); if ($collection == StorageInterface::DEFAULT_COLLECTION) { only in patch2: unchanged: --- a/core/core.services.yml +++ b/core/core.services.yml @@ -45,6 +45,13 @@ services: factory_method: get factory_service: cache_factory arguments: [bootstrap] + cache.config: + class: Drupal\Core\Cache\CacheBackendInterface + tags: + - { name: cache.bin } + factory_method: get + factory_service: cache_factory + arguments: [config] cache.default: class: Drupal\Core\Cache\CacheBackendInterface tags: only in patch2: unchanged: --- a/core/modules/config/src/Tests/Storage/CachedStorageTest.php +++ b/core/modules/config/src/Tests/Storage/CachedStorageTest.php @@ -37,7 +37,7 @@ class CachedStorageTest extends ConfigStorageTestBase { protected function setUp() { parent::setUp(); $this->filestorage = new FileStorage($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]); - $this->storage = new CachedStorage($this->filestorage, \Drupal::service('cache_factory')); + $this->storage = new CachedStorage($this->filestorage, \Drupal::service('cache.config')); $this->cache = \Drupal::service('cache_factory')->get('config'); // ::listAll() verifications require other configuration data to exist. $this->storage->write('system.performance', array());