diff --git a/core/core.services.yml b/core/core.services.yml index f835186..4e1b13b 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -38,7 +38,7 @@ services: - [setContainer, ['@service_container']] tags: - { name: service_collector, call: addInvalidator } - cache_tags_storage: + cache_tags.checksum: class: Drupal\Core\Cache\DatabaseCacheTagsStorage arguments: ['@database'] tags: @@ -50,13 +50,13 @@ services: - [setContainer, ['@service_container']] cache.backend.database: class: Drupal\Core\Cache\DatabaseBackendFactory - arguments: ['@database', '@cache_tags_storage'] + arguments: ['@database', '@cache_tags.checksum'] cache.backend.apcu: class: Drupal\Core\Cache\ApcuBackendFactory - arguments: ['@app.root', '@cache_tags_storage'] + arguments: ['@app.root', '@cache_tags.checksum'] cache.backend.php: class: Drupal\Core\Cache\PhpBackendFactory - arguments: ['@cache_tags_storage'] + arguments: ['@cache_tags.checksum'] cache.bootstrap: class: Drupal\Core\Cache\CacheBackendInterface tags: diff --git a/core/lib/Drupal/Core/Cache/ApcuBackend.php b/core/lib/Drupal/Core/Cache/ApcuBackend.php index e5e9f64..e406d0f 100644 --- a/core/lib/Drupal/Core/Cache/ApcuBackend.php +++ b/core/lib/Drupal/Core/Cache/ApcuBackend.php @@ -45,11 +45,11 @@ class ApcuBackend implements CacheBackendInterface, CacheTagsInvalidatorInterfac protected $invalidationsTagsPrefix; /** - * The cache tags storage. + * The cache tags checksum provider. * - * @var \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface + * @var \Drupal\Core\Cache\CacheTagsChecksumInterface */ - protected $cacheTagsStorage; + protected $checksumProvider; /** * A static cache of all tags checked during the request. @@ -65,13 +65,13 @@ class ApcuBackend implements CacheBackendInterface, CacheTagsInvalidatorInterfac * The name of the cache bin. * @param string $site_prefix * The prefix to use for all keys in the storage that belong to this site. - * @param \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface $cache_tags_storage - * Cache tags storage. + * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider + * The cache tags checksum provider. */ - public function __construct($bin, $site_prefix, CacheTagsInvalidationStorageInterface $cache_tags_storage) { + public function __construct($bin, $site_prefix, CacheTagsChecksumInterface $checksum_provider) { $this->bin = $bin; $this->sitePrefix = $site_prefix; - $this->cacheTagsStorage = $cache_tags_storage; + $this->checksumProvider = $checksum_provider; $this->binPrefix = $this->sitePrefix . '::' . $this->bin . '::'; $this->invalidationsTagsPrefix = $this->sitePrefix . '::itags::'; } @@ -168,7 +168,7 @@ protected function prepareItem($cache, $allow_invalid) { $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME; // Check if invalidateTags() has been called with any of the entry's tags. - if ($cache->checksum != $this->cacheTagsStorage->checksumTags($cache->tags)) { + if (!$this->checksumProvider->isValid($cache->checksum, $cache->tags)) { $cache->valid = FALSE; } @@ -186,7 +186,6 @@ public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANEN if ($tags) { $tags = array_unique($tags); Cache::validateTags($tags); - $this->cacheTagsStorage->onCacheTagsWrite($tags); } $cache = new \stdClass(); @@ -194,7 +193,7 @@ public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANEN $cache->created = round(microtime(TRUE), 3); $cache->expire = $expire; $cache->tags = implode(' ', $tags); - $cache->checksum = $this->cacheTagsStorage->checksumTags($tags);; + $cache->checksum = $this->checksumProvider->getCurrentChecksum($tags); // APC serializes/unserializes any structure itself. $cache->serialized = 0; $cache->data = $data; diff --git a/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php index b1ffc4a..bbc4e3d 100644 --- a/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php @@ -19,23 +19,23 @@ class ApcuBackendFactory implements CacheFactoryInterface { protected $sitePrefix; /** - * The cache tags storage. + * The cache tags checksum provider. * - * @var \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface + * @var \Drupal\Core\Cache\CacheTagsChecksumInterface */ - protected $cacheTagsStorage; + protected $checksumProvider; /** * Constructs an ApcuBackendFactory object. * * @param string $root * The app root. - * @param \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface $cache_tags_storage - * Cache tags storage. + * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider + * The cache tags checksum provider. */ - public function __construct($root, CacheTagsInvalidationStorageInterface $cache_tags_storage) { + public function __construct($root, CacheTagsChecksumInterface $checksum_provider) { $this->sitePrefix = Crypt::hashBase64($root . '/' . conf_path()); - $this->cacheTagsStorage = $cache_tags_storage; + $this->checksumProvider = $checksum_provider; } /** @@ -48,7 +48,7 @@ public function __construct($root, CacheTagsInvalidationStorageInterface $cache_ * The cache backend object for the specified cache bin. */ public function get($bin) { - return new ApcuBackend($bin, $this->sitePrefix, $this->cacheTagsStorage); + return new ApcuBackend($bin, $this->sitePrefix, $this->checksumProvider); } } diff --git a/core/lib/Drupal/Core/Cache/CacheTagsChecksumInterface.php b/core/lib/Drupal/Core/Cache/CacheTagsChecksumInterface.php new file mode 100644 index 0000000..265f624 --- /dev/null +++ b/core/lib/Drupal/Core/Cache/CacheTagsChecksumInterface.php @@ -0,0 +1,55 @@ +bin = $bin; $this->connection = $connection; - $this->cacheTagStorage = $cacheTagStorage; + $this->checksumProvider = $checksum_provider; } /** @@ -129,8 +129,8 @@ protected function prepareItem($cache, $allow_invalid) { // Check expire time. $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME; - // Check if invalidateTags() has been called with any of the entry's tags. - if ($cache->checksum != $this->cacheTagStorage->checksumTags($cache->tags)) { + // Check if invalidateTags() has been called with any of the items's tags. + if (!$this->checksumProvider->isValid($cache->checksum, $cache->tags)) { $cache->valid = FALSE; } @@ -155,7 +155,6 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array $tags = array_unique($tags); // Sort the cache tags so that they are stored consistently in the database. sort($tags); - $this->cacheTagStorage->onCacheTagsWrite($tags); } $try_again = FALSE; try { @@ -184,7 +183,7 @@ protected function doSet($cid, $data, $expire, $tags) { 'created' => round(microtime(TRUE), 3), 'expire' => $expire, 'tags' => implode(' ', $tags), - 'checksum' => $this->cacheTagStorage->checksumTags($tags), + 'checksum' => $this->checksumProvider->getCurrentChecksum($tags), ); if (!is_string($data)) { $fields['data'] = serialize($data); @@ -229,7 +228,6 @@ public function setMultiple(array $items) { $item['tags'] = array_unique($item['tags']); // Sort the cache tags so that they are stored consistently in the DB. sort($item['tags']); - $this->cacheTagStorage->onCacheTagsWrite($item['tags']); } $fields = array( @@ -237,7 +235,7 @@ public function setMultiple(array $items) { 'expire' => $item['expire'], 'created' => round(microtime(TRUE), 3), 'tags' => implode(' ', $item['tags']), - 'checksum' => $this->cacheTagStorage->checksumTags($item['tags']), + 'checksum' => $this->checksumProvider->getCurrentChecksum($item['tags']), ); if (!is_string($item['data'])) { diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php b/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php index cc3d0cb..59b0b22 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php @@ -19,23 +19,23 @@ class DatabaseBackendFactory implements CacheFactoryInterface { protected $connection; /** - * The cache tags storage. + * The cache tags checksum provider. * - * @var \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface + * @var \Drupal\Core\Cache\CacheTagsChecksumInterface */ - protected $cacheTagsStorage; + protected $checksumProvider; /** * Constructs the DatabaseBackendFactory object. * * @param \Drupal\Core\Database\Connection $connection * Database connection - * @param \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface $cache_tags_storage - * Cache tags storage. + * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider + * The cache tags checksum provider. */ - function __construct(Connection $connection, CacheTagsInvalidationStorageInterface $cache_tags_storage) { + function __construct(Connection $connection, CacheTagsChecksumInterface $checksum_provider) { $this->connection = $connection; - $this->cacheTagsStorage = $cache_tags_storage; + $this->checksumProvider = $checksum_provider; } /** @@ -48,7 +48,7 @@ function __construct(Connection $connection, CacheTagsInvalidationStorageInterfa * The cache backend object for the specified cache bin. */ function get($bin) { - return new DatabaseBackend($this->connection, $this->cacheTagsStorage, $bin); + return new DatabaseBackend($this->connection, $this->checksumProvider, $bin); } } diff --git a/core/lib/Drupal/Core/Cache/DatabaseCacheTagsStorage.php b/core/lib/Drupal/Core/Cache/DatabaseCacheTagsChecksum.php similarity index 94% rename from core/lib/Drupal/Core/Cache/DatabaseCacheTagsStorage.php rename to core/lib/Drupal/Core/Cache/DatabaseCacheTagsChecksum.php index b8c0556..0a519f4 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseCacheTagsStorage.php +++ b/core/lib/Drupal/Core/Cache/DatabaseCacheTagsChecksum.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Cache\DatabaseCacheTagsStorage. + * Contains \Drupal\Core\Cache\DatabaseCacheTagsChecksum. */ namespace Drupal\Core\Cache; @@ -13,7 +13,7 @@ /** * Storage for cache tag invalidations. */ -class DatabaseCacheTagsStorage implements CacheTagsInvalidationStorageInterface, CacheTagsInvalidatorInterface { +class DatabaseCacheTagsChecksum implements CacheTagsChecksumInterface, CacheTagsInvalidatorInterface { /** * The database connection. @@ -39,7 +39,7 @@ class DatabaseCacheTagsStorage implements CacheTagsInvalidationStorageInterface, protected $invalidatedTags = array(); /** - * Constructs a DatabaseCacheTagsStorage object. + * Constructs a DatabaseCacheTagsChecksum object. * * @param \Drupal\Core\Database\Connection $connection * The database connection. @@ -80,7 +80,7 @@ public function invalidateTags(array $tags) { /** * {@inheritdoc} */ - public function checksumTags(array $tags) { + public function getCurrentChecksum(array $tags) { $checksum = 0; $query_tags = array_diff($tags, array_keys($this->tagCache)); diff --git a/core/lib/Drupal/Core/Cache/PhpBackend.php b/core/lib/Drupal/Core/Cache/PhpBackend.php index 99e7598..7bcf861 100644 --- a/core/lib/Drupal/Core/Cache/PhpBackend.php +++ b/core/lib/Drupal/Core/Cache/PhpBackend.php @@ -36,23 +36,23 @@ class PhpBackend implements CacheBackendInterface { protected $cache = array(); /** - * The cache tags storage. + * The cache tags checksum provider. * - * @var \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface + * @var \Drupal\Core\Cache\CacheTagsChecksumInterface */ - protected $cacheTagsStorage; + protected $checksumProvider; /** * Constructs a PhpBackend object. * * @param string $bin * The cache bin for which the object is created. - * @param \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface $cache_tags_storage - * Cache tags storage. + * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider + * The cache tags checksum provider. */ - public function __construct($bin, CacheTagsInvalidationStorageInterface $cache_tags_storage) { + public function __construct($bin, CacheTagsChecksumInterface $checksum_provider) { $this->bin = 'cache_' . $bin; - $this->cacheTagsStorage = $cache_tags_storage; + $this->checksumProvider = $checksum_provider; } /** @@ -133,7 +133,7 @@ protected function prepareItem($cache, $allow_invalid) { $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME; // Check if invalidateTags() has been called with any of the item's tags. - if ($cache->checksum != $this->cacheTagsStorage->checksumTags($cache->tags)) { + if (!$this->checksumProvider->isValid($cache->checksums, $cache->tags)) { $cache->valid = FALSE; } @@ -151,7 +151,7 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array if ($tags) { $tags = array_unique($tags); Cache::validateTags($tags); - $this->cacheTagsStorage->onCacheTagsWrite($tags); + $this->checksumProvider->onCacheTagsWrite($tags); } $item = (object) array( 'cid' => $cid, @@ -159,7 +159,7 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array 'created' => round(microtime(TRUE), 3), 'expire' => $expire, 'tags' => $tags, - 'checksum' => $this->cacheTagsStorage->checksumTags($tags), + 'checksum' => $this->checksumProvider->getCurrentChecksum($tags), ); $this->writeItem($this->normalizeCid($cid), $item); } diff --git a/core/lib/Drupal/Core/Cache/PhpBackendFactory.php b/core/lib/Drupal/Core/Cache/PhpBackendFactory.php index c0f7096..dde93d4 100644 --- a/core/lib/Drupal/Core/Cache/PhpBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/PhpBackendFactory.php @@ -10,20 +10,20 @@ class PhpBackendFactory implements CacheFactoryInterface { /** - * The cache tags storage. + * The cache tags checksum provider. * - * @var \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface + * @var \Drupal\Core\Cache\CacheTagsChecksumInterface */ - protected $cacheTagsStorage; + protected $checksumProvider; /** * Constructs a PhpBackendFactory object. * - * @param \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface $cache_tags_storage - * Cache tags storage. + * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider + * The cache tags checksum provider. */ - public function __construct(CacheTagsInvalidationStorageInterface $cache_tags_storage) { - $this->cacheTagsStorage = $cache_tags_storage; + public function __construct(CacheTagsChecksumInterface $checksum_provider) { + $this->checksumProvider = $checksum_provider; } /** @@ -36,7 +36,7 @@ public function __construct(CacheTagsInvalidationStorageInterface $cache_tags_st * The cache backend object for the specified cache bin. */ function get($bin) { - return new PhpBackend($bin, $this->cacheTagsStorage); + return new PhpBackend($bin, $this->checksumProvider); } } diff --git a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php index 45f4396..851ae71 100644 --- a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php +++ b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php @@ -52,7 +52,7 @@ public function register(ContainerBuilder $container) { // Remove the cache tags invalidator tag from the cache tags storage, so // that we don't call it when cache tags are invalidated very early in the // installer. - $container->getDefinition('cache_tags_storage') + $container->getDefinition('cache_tags.checksum') ->clearTag('cache_tags_invalidator'); // Replace the route builder with an empty implementation. diff --git a/core/modules/config/src/Tests/Storage/CachedStorageTest.php b/core/modules/config/src/Tests/Storage/CachedStorageTest.php index 8a71f1f..f7dd32e 100644 --- a/core/modules/config/src/Tests/Storage/CachedStorageTest.php +++ b/core/modules/config/src/Tests/Storage/CachedStorageTest.php @@ -91,7 +91,7 @@ public function containerBuild(ContainerBuilder $container) { // Use the regular database cache backend to aid testing. $container->register('cache_factory', 'Drupal\Core\Cache\DatabaseBackendFactory') ->addArgument(new Reference('database')) - ->addArgument(new Reference('cache_tags_storage')); + ->addArgument(new Reference('cache_tags.checksum')); } } diff --git a/core/modules/locale/src/Tests/LocaleTranslationUiTest.php b/core/modules/locale/src/Tests/LocaleTranslationUiTest.php index 774aee2..f918e1e 100644 --- a/core/modules/locale/src/Tests/LocaleTranslationUiTest.php +++ b/core/modules/locale/src/Tests/LocaleTranslationUiTest.php @@ -137,7 +137,7 @@ public function testStringTranslation() { // Reset the tag cache on the tester side in order to pick up the call to // Cache::invalidateTags() on the tested side. - \Drupal::service('cache_tags_storage')->reset(); + \Drupal::service('cache_tags.checksum')->reset(); $this->assertTrue($name != $translation && t($name, array(), array('langcode' => $langcode)) == $translation, 't() works for non-English.'); // Refresh the locale() cache to get fresh data from t() below. We are in diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index b1f52a6..51e5940 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -1151,7 +1151,7 @@ protected function resetAll() { */ protected function refreshVariables() { // Clear the tag cache. - \Drupal::service('cache_tags_storage')->reset(); + \Drupal::service('cache_tags.checksum')->reset(); foreach (Cache::getBins() as $backend) { if (is_callable(array($backend, 'reset'))) { $backend->reset(); diff --git a/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php b/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php index ad1dc81..14bb16c 100644 --- a/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php +++ b/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php @@ -34,7 +34,7 @@ protected function checkRequirements() { } protected function createCacheBackend($bin) { - $backend = new ApcuBackend($bin, $this->databasePrefix, \Drupal::service('cache_tags_storage')); + $backend = new ApcuBackend($bin, $this->databasePrefix, \Drupal::service('cache_tags.checksum')); return $backend; } diff --git a/core/modules/system/src/Tests/Cache/ChainedFastBackendUnitTest.php b/core/modules/system/src/Tests/Cache/ChainedFastBackendUnitTest.php index 6b06d04..74d19d7 100644 --- a/core/modules/system/src/Tests/Cache/ChainedFastBackendUnitTest.php +++ b/core/modules/system/src/Tests/Cache/ChainedFastBackendUnitTest.php @@ -25,8 +25,8 @@ class ChainedFastBackendUnitTest extends GenericCacheBackendUnitTestBase { * A new ChainedFastBackend object. */ protected function createCacheBackend($bin) { - $consistent_backend = new DatabaseBackend(\Drupal::service('database'), \Drupal::service('cache_tags_storage'), $bin); - $fast_backend = new PhpBackend($bin, \Drupal::service('cache_tags_storage')); + $consistent_backend = new DatabaseBackend(\Drupal::service('database'), \Drupal::service('cache_tags.checksum'), $bin); + $fast_backend = new PhpBackend($bin, \Drupal::service('cache_tags.checksum')); return new ChainedFastBackend($consistent_backend, $fast_backend, $bin); } diff --git a/core/modules/system/src/Tests/Cache/DatabaseBackendUnitTest.php b/core/modules/system/src/Tests/Cache/DatabaseBackendUnitTest.php index b458996..91009f8 100644 --- a/core/modules/system/src/Tests/Cache/DatabaseBackendUnitTest.php +++ b/core/modules/system/src/Tests/Cache/DatabaseBackendUnitTest.php @@ -30,7 +30,7 @@ class DatabaseBackendUnitTest extends GenericCacheBackendUnitTestBase { * A new DatabaseBackend object. */ protected function createCacheBackend($bin) { - return new DatabaseBackend($this->container->get('database'), $this->container->get('cache_tags_storage'), $bin); + return new DatabaseBackend($this->container->get('database'), $this->container->get('cache_tags.checksum'), $bin); } } diff --git a/core/modules/system/src/Tests/Cache/PhpBackendUnitTest.php b/core/modules/system/src/Tests/Cache/PhpBackendUnitTest.php index e19cf35..507c16f 100644 --- a/core/modules/system/src/Tests/Cache/PhpBackendUnitTest.php +++ b/core/modules/system/src/Tests/Cache/PhpBackendUnitTest.php @@ -23,7 +23,7 @@ class PhpBackendUnitTest extends GenericCacheBackendUnitTestBase { * A new MemoryBackend object. */ protected function createCacheBackend($bin) { - $backend = new PhpBackend($bin, \Drupal::service('cache_tags_storage')); + $backend = new PhpBackend($bin, \Drupal::service('cache_tags.checksum')); return $backend; }