diff --git a/core/core.services.yml b/core/core.services.yml index e72f259..7f9afc6 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -32,15 +32,17 @@ services: class: Drupal\Core\Cache\TimeZoneCacheContext tags: - { name: cache.context} - cache_tags: - class: Drupal\Core\Cache\CacheTagHandler + cache_tags_invalidator: + class: Drupal\Core\Cache\CacheTagsInvalidator + calls: + - [setContainer, ['@service_container']] tags: - - { name: service_collector } - cache_tag_storage: - class: Drupal\Core\Cache\DatabaseCacheTagStorage + - { name: service_collector, call: addInvalidator } + cache_tags_storage: + class: Drupal\Core\Cache\DatabaseCacheTagsStorage arguments: ['@database'] tags: - - { name: cache_tags } + - { name: cache_tags_invalidator} cache.backend.chainedfast: class: Drupal\Core\Cache\ChainedFastBackendFactory arguments: ['@settings'] @@ -48,16 +50,12 @@ services: - [setContainer, ['@service_container']] cache.backend.database: class: Drupal\Core\Cache\DatabaseBackendFactory - arguments: ['@database', '@cache_tag_storage'] + arguments: ['@database', '@cache_tags_storage'] cache.backend.apcu: class: Drupal\Core\Cache\ApcuBackendFactory arguments: ['@app.root'] - tags: - - { name: cache_tags } cache.backend.php: class: Drupal\Core\Cache\PhpBackendFactory - tags: - - { name: cache_tags } cache.bootstrap: class: Drupal\Core\Cache\CacheBackendInterface tags: @@ -111,7 +109,6 @@ services: class: Drupal\Core\Cache\CacheBackendInterface tags: - { name: cache.bin, default_backend: cache.backend.chainedfast } - - { name: cache_tags } factory_method: get factory_service: cache_factory arguments: [discovery] diff --git a/core/lib/Drupal/Core/Cache/ApcuBackend.php b/core/lib/Drupal/Core/Cache/ApcuBackend.php index b42a053..d7bdbdb 100644 --- a/core/lib/Drupal/Core/Cache/ApcuBackend.php +++ b/core/lib/Drupal/Core/Cache/ApcuBackend.php @@ -10,7 +10,7 @@ /** * Stores cache items in the Alternative PHP Cache User Cache (APCu). */ -class ApcuBackend implements CacheBackendInterface { +class ApcuBackend implements CacheBackendInterface, CacheTagsInvalidatorInterface { /** * The name of the cache bin to use. @@ -45,6 +45,13 @@ class ApcuBackend implements CacheBackendInterface { protected $invalidationsTagsPrefix; /** + * The cache tags storage. + * + * @var \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface + */ + protected $cacheTagsStorage; + + /** * A static cache of all tags checked during the request. * * @var array @@ -58,10 +65,13 @@ class ApcuBackend implements CacheBackendInterface { * 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. */ - public function __construct($bin, $site_prefix) { + public function __construct($bin, $site_prefix, CacheTagsInvalidationStorageInterface $cache_tags_storage) { $this->bin = $bin; $this->sitePrefix = $site_prefix; + $this->cacheTagsStorage = $cache_tags_storage; $this->binPrefix = $this->sitePrefix . '::' . $this->bin . '::'; $this->invalidationsTagsPrefix = $this->sitePrefix . '::itags::'; } @@ -153,7 +163,7 @@ protected function prepareItem($cache, $allow_invalid) { } $cache->tags = $cache->tags ? explode(' ', $cache->tags) : array(); - $checksum = $this->checksumTags($cache->tags); + $checksum = $this->cacheTagsStorage->checksumTags($cache->tags); // Check expire time. $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME; @@ -174,14 +184,18 @@ protected function prepareItem($cache, $allow_invalid) { * {@inheritdoc} */ public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) { - Cache::validateTags($tags); + if ($tags) { + Cache::validateTags($tags); + $this->cacheTagsStorage->onCacheTagsWrite($tags); + } + $tags = array_unique($tags); $cache = new \stdClass(); $cache->cid = $cid; $cache->created = round(microtime(TRUE), 3); $cache->expire = $expire; $cache->tags = implode(' ', $tags); - $checksum = $this->checksumTags($tags); + $checksum = $this->cacheTagsStorage->checksumTags($tags); $cache->checksum_invalidations = $checksum; // APC serializes/unserializes any structure itself. $cache->serialized = 0; @@ -279,37 +293,4 @@ public function invalidateTags(array $tags) { } } - /** - * Returns the sum total of validations for a given set of tags. - * - * @param array $tags - * Associative array of tags. - * - * @return int - * Sum of all invalidations. - */ - protected function checksumTags(array $tags) { - $checksum = 0; - $query_tags = array(); - - foreach ($tags as $tag) { - if (isset(static::$tagCache[$tag])) { - $checksum += static::$tagCache[$tag]; - } - else { - $query_tags[] = $this->invalidationsTagsPrefix . $tag; - } - } - - if ($query_tags) { - $result = apc_fetch($query_tags); - if ($result) { - static::$tagCache = array_merge(static::$tagCache, $result); - $checksum += array_sum($result); - } - } - - return $checksum; - } - } diff --git a/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php index 0f5f362..b2e27e5 100644 --- a/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php @@ -9,7 +9,7 @@ use \Drupal\Component\Utility\Crypt; -class ApcuBackendFactory implements CacheFactoryInterface, CacheTagInvalidationInterface { +class ApcuBackendFactory implements CacheFactoryInterface { /** * The site prefix string. @@ -19,13 +19,23 @@ class ApcuBackendFactory implements CacheFactoryInterface, CacheTagInvalidationI protected $sitePrefix; /** + * The cache tags storage. + * + * @var \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface + */ + protected $cacheTagsStorage; + + /** * Constructs an ApcuBackendFactory object. * * @param string $root * The app root. + * @param \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface $cache_tags_storage + * Cache tags storage. */ - public function __construct($root) { + public function __construct($root, CacheTagsInvalidationStorageInterface $cache_tags_storage, CacheTagsInvalidationStorageInterface $cache_tags_storage) { $this->sitePrefix = Crypt::hashBase64($root . '/' . conf_path()); + $this->cacheTagsStorage = $cache_tags_storage; } /** @@ -38,23 +48,7 @@ public function __construct($root) { * The cache backend object for the specified cache bin. */ public function get($bin) { - return new ApcuBackend($bin, $this->sitePrefix); + return new ApcuBackend($bin, $this->sitePrefix, $this->cacheTagsStorage); } - /** - * Marks cache items with any of the specified tags as invalid. - * - * @param array $tags - * Associative array of tags, in the same format that is passed to - * CacheBackendInterface::set(). - * - * @see \Drupal\Core\Cache\CacheBackendInterface::set() - * @see \Drupal\Core\Cache\CacheTagInvalidationInterface::invalidateTags() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidate() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateAll() - */ - public function invalidateTags(array $tags) { - // TODO: Implement invalidateTags() method. - } } diff --git a/core/lib/Drupal/Core/Cache/BackendChain.php b/core/lib/Drupal/Core/Cache/BackendChain.php index d2aff4a..f7681d9 100644 --- a/core/lib/Drupal/Core/Cache/BackendChain.php +++ b/core/lib/Drupal/Core/Cache/BackendChain.php @@ -23,7 +23,7 @@ * @ingroup cache */ -class BackendChain implements CacheBackendInterface { +class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterface { /** * Ordered list of CacheBackendInterface instances. @@ -190,7 +190,9 @@ public function invalidateMultiple(array $cids) { */ public function invalidateTags(array $tags) { foreach ($this->backends as $backend) { - $backend->invalidateTags($tags); + if ($backend instanceof CacheTagsInvalidatorInterface) { + $backend->invalidateTags($tags); + } } } diff --git a/core/lib/Drupal/Core/Cache/Cache.php b/core/lib/Drupal/Core/Cache/Cache.php index bdf7fb4..a38df0e 100644 --- a/core/lib/Drupal/Core/Cache/Cache.php +++ b/core/lib/Drupal/Core/Cache/Cache.php @@ -100,9 +100,7 @@ public static function buildTags($prefix, array $suffixes) { * The list of tags to invalidate cache items for. */ public static function invalidateTags(array $tags) { - // @todo Move to service. - static::validateTags($tags); - \Drupal::service('cache_tags')->invalidateTags($tags); + \Drupal::service('cache_tags_invalidator')->invalidateTags($tags); } /** diff --git a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php index b37ad95..e5aa85d 100644 --- a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php +++ b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php @@ -18,7 +18,7 @@ * * @ingroup cache */ -interface CacheBackendInterface extends CacheTagInvalidationInterface { +interface CacheBackendInterface { /** * Indicates that the item should never be removed unless explicitly deleted. diff --git a/core/lib/Drupal/Core/Cache/CacheTagHandler.php b/core/lib/Drupal/Core/Cache/CacheTagHandler.php deleted file mode 100644 index b5d7174..0000000 --- a/core/lib/Drupal/Core/Cache/CacheTagHandler.php +++ /dev/null @@ -1,32 +0,0 @@ -invalidators as $invalidator) { - $invalidator->invalidateTags($tags); - } - } - - public function addHandler(CacheTagInvalidationInterface $service) { - $this->invalidators[] = $service; - } - -} diff --git a/core/lib/Drupal/Core/Cache/CacheTagInvalidationInterface.php b/core/lib/Drupal/Core/Cache/CacheTagInvalidationInterface.php deleted file mode 100644 index f5452c9..0000000 --- a/core/lib/Drupal/Core/Cache/CacheTagInvalidationInterface.php +++ /dev/null @@ -1,29 +0,0 @@ -invalidators as $invalidator) { + $invalidator->invalidateTags($tags); + } + + // Additionally, notify each cache bin if it implements the service. + foreach ($this->getBins() as $bin) { + if ($bin instanceof CacheTagsInvalidatorInterface) { + $bin->invalidateTags($tags); + } + } + + } + + /** + * Adds a cache tag invalidator. + * + * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $invalidator + * A cache invalidator. + */ + public function addInvalidator(CacheTagsInvalidatorInterface $invalidator) { + $this->invalidators[] = $invalidator; + } + + /** + * Gets all cache bin services. + * + * @return \Drupal\Core\Cache\CacheBackendInterface + * An array of cache backend objects keyed by cache bins. + */ + protected function getBins() { + $bins = array(); + foreach ($this->container->getParameter('cache_bins') as $service_id => $bin) { + $bins[$bin] = $this->container->get($service_id); + } + return $bins; + } + +} diff --git a/core/lib/Drupal/Core/Cache/CacheTagHandlerInterface.php b/core/lib/Drupal/Core/Cache/CacheTagsInvalidatorInterface.php similarity index 77% rename from core/lib/Drupal/Core/Cache/CacheTagHandlerInterface.php rename to core/lib/Drupal/Core/Cache/CacheTagsInvalidatorInterface.php index 88cc26a..e84eb38 100644 --- a/core/lib/Drupal/Core/Cache/CacheTagHandlerInterface.php +++ b/core/lib/Drupal/Core/Cache/CacheTagsInvalidatorInterface.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Cache\CacheTagHandlerInterface + * Contains \Drupal\Core\Cache\CacheTagsInvalidatorInterface */ namespace Drupal\Core\Cache; @@ -10,7 +10,7 @@ /** * Defines required methods for classes wanting to handle cache tag changes. */ -interface CacheTagHandlerInterface { +interface CacheTagsInvalidatorInterface { /** * Marks cache items with any of the specified tags as invalid. diff --git a/core/lib/Drupal/Core/Cache/ChainedFastBackend.php b/core/lib/Drupal/Core/Cache/ChainedFastBackend.php index 0f733c1..e373b12 100644 --- a/core/lib/Drupal/Core/Cache/ChainedFastBackend.php +++ b/core/lib/Drupal/Core/Cache/ChainedFastBackend.php @@ -41,7 +41,7 @@ * * @ingroup cache */ -class ChainedFastBackend implements CacheBackendInterface { +class ChainedFastBackend implements CacheBackendInterface, CacheTagsInvalidatorInterface { /** * Cache key prefix for the bin-specific entry to track the last write. @@ -228,7 +228,9 @@ public function invalidateMultiple(array $cids) { * {@inheritdoc} */ public function invalidateTags(array $tags) { - $this->consistentBackend->invalidateTags($tags); + if ($this->consistentBackend instanceof CacheTagsInvalidatorInterface) { + $this->consistentBackend->invalidateTags($tags); + } $this->markAsOutdated(); } diff --git a/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php b/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php index 4f7f4cd..70794b2 100644 --- a/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php @@ -12,7 +12,7 @@ /** * Defines the chained fast cache backend factory. */ -class ChainedFastBackendFactory implements CacheFactoryInterface, CacheTagInvalidationInterface { +class ChainedFastBackendFactory implements CacheFactoryInterface { use ContainerAwareTrait; @@ -85,19 +85,4 @@ public function get($bin) { } } - /** - * Marks cache items with any of the specified tags as invalid. - * - * @param array $tags - * Associative array of tags, in the same format that is passed to - * CacheBackendInterface::set(). - * - * @see \Drupal\Core\Cache\CacheBackendInterface::set() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidate() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateAll() - */ - public function invalidateTags(array $tags) { - // TODO: Implement invalidateTags() method. - } } diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackend.php b/core/lib/Drupal/Core/Cache/DatabaseBackend.php index a379133..181dbd7 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseBackend.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php @@ -37,7 +37,7 @@ class DatabaseBackend implements CacheBackendInterface { /** * Storage for cache tag invalidations. * - * @var \Drupal\Core\Cache\CacheTagInvalidationStorageInterface + * @var \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface */ protected $cacheTagStorage; @@ -46,12 +46,12 @@ class DatabaseBackend implements CacheBackendInterface { * * @param \Drupal\Core\Database\Connection $connection * The database connection. - * @param \Drupal\Core\Cache\CacheTagInvalidationStorageInterface $cacheTagStorage + * @param \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface $cacheTagStorage * The object that stores cache tag invalidations. * @param string $bin * The cache bin for which the object is created. */ - public function __construct(Connection $connection, CacheTagInvalidationStorageInterface $cacheTagStorage, $bin) { + public function __construct(Connection $connection, CacheTagsInvalidationStorageInterface $cacheTagStorage, $bin) { // All cache tables should be prefixed with 'cache_'. $bin = 'cache_' . $bin; @@ -340,11 +340,6 @@ public function invalidateMultiple(array $cids) { } /** - * Implements Drupal\Core\Cache\CacheTagHandlerInterface::invalidateTags(). - */ - public function invalidateTags(array $tags) {} - - /** * Implements Drupal\Core\Cache\CacheBackendInterface::invalidateAll(). */ public function invalidateAll() { diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php b/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php index 2772bab..cc3d0cb 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php @@ -19,13 +19,23 @@ class DatabaseBackendFactory implements CacheFactoryInterface { protected $connection; /** + * The cache tags storage. + * + * @var \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface + */ + protected $cacheTagsStorage; + + /** * Constructs the DatabaseBackendFactory object. * * @param \Drupal\Core\Database\Connection $connection + * Database connection + * @param \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface $cache_tags_storage + * Cache tags storage. */ - function __construct(Connection $connection, CacheTagInvalidationStorageInterface $cacheTagStorage) { + function __construct(Connection $connection, CacheTagsInvalidationStorageInterface $cache_tags_storage) { $this->connection = $connection; - $this->cacheTagStorage = $cacheTagStorage; + $this->cacheTagsStorage = $cache_tags_storage; } /** @@ -38,7 +48,7 @@ function __construct(Connection $connection, CacheTagInvalidationStorageInterfac * The cache backend object for the specified cache bin. */ function get($bin) { - return new DatabaseBackend($this->connection, $this->cacheTagStorage, $bin); + return new DatabaseBackend($this->connection, $this->cacheTagsStorage, $bin); } } diff --git a/core/lib/Drupal/Core/Cache/DatabaseCacheTagStorage.php b/core/lib/Drupal/Core/Cache/DatabaseCacheTagsStorage.php similarity index 96% rename from core/lib/Drupal/Core/Cache/DatabaseCacheTagStorage.php rename to core/lib/Drupal/Core/Cache/DatabaseCacheTagsStorage.php index 17a89f9..9823227 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseCacheTagStorage.php +++ b/core/lib/Drupal/Core/Cache/DatabaseCacheTagsStorage.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Cache\DatabaseCacheTagStorage. + * Contains \Drupal\Core\Cache\DatabaseCacheTagsStorage. */ namespace Drupal\Core\Cache; @@ -13,7 +13,7 @@ /** * Storage for cache tag invalidations. */ -class DatabaseCacheTagStorage implements CacheTagInvalidationStorageInterface, CacheTagInvalidationInterface { +class DatabaseCacheTagsStorage implements CacheTagsInvalidationStorageInterface, CacheTagsInvalidatorInterface { /** * The database connection. diff --git a/core/lib/Drupal/Core/Cache/MemoryBackend.php b/core/lib/Drupal/Core/Cache/MemoryBackend.php index b9d951b..5d7cfab 100644 --- a/core/lib/Drupal/Core/Cache/MemoryBackend.php +++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php @@ -17,7 +17,7 @@ * * @ingroup cache */ -class MemoryBackend implements CacheBackendInterface { +class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterface { /** * Array to store cache objects. @@ -169,7 +169,7 @@ public function invalidateMultiple(array $cids) { } /** - * Implements Drupal\Core\Cache\CacheBackendInterface::invalidateTags(). + * {@inheritdoc} */ public function invalidateTags(array $tags) { foreach ($this->cache as $cid => $item) { diff --git a/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php b/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php index af7f605..53e5b07 100644 --- a/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/MemoryBackendFactory.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Cache; -class MemoryBackendFactory implements CacheFactoryInterface, CacheTagInvalidationInterface { +class MemoryBackendFactory implements CacheFactoryInterface { /** * Instantiated memory cache bins. @@ -26,12 +26,4 @@ function get($bin) { return $this->bins[$bin]; } - /** - * {@inheritdoc} - */ - public function invalidateTags(array $tags) { - foreach ($this->bins as $bin) { - $bin->invalidateTags($tags); - } - } } diff --git a/core/lib/Drupal/Core/Cache/NullBackend.php b/core/lib/Drupal/Core/Cache/NullBackend.php index a97b3cc..852da7b 100644 --- a/core/lib/Drupal/Core/Cache/NullBackend.php +++ b/core/lib/Drupal/Core/Cache/NullBackend.php @@ -80,11 +80,6 @@ public function invalidate($cid) {} public function invalidateMultiple(array $cids) {} /** - * Implements Drupal\Core\Cache\CacheTagInvalidationInterface::invalidateTags(). - */ - public function invalidateTags(array $tags) {} - - /** * Implements Drupal\Core\Cache\CacheBackendInterface::invalidateAll(). */ public function invalidateAll() {} diff --git a/core/lib/Drupal/Core/Cache/NullBackendFactory.php b/core/lib/Drupal/Core/Cache/NullBackendFactory.php index 058a9e4..0101a8e 100644 --- a/core/lib/Drupal/Core/Cache/NullBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/NullBackendFactory.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Cache; -class NullBackendFactory implements CacheFactoryInterface, CacheTagInvalidationInterface { +class NullBackendFactory implements CacheFactoryInterface { /** * {@inheritdoc} @@ -16,19 +16,4 @@ function get($bin) { return new NullBackend($bin); } - /** - * Marks cache items with any of the specified tags as invalid. - * - * @param array $tags - * Associative array of tags, in the same format that is passed to - * CacheBackendInterface::set(). - * - * @see \Drupal\Core\Cache\CacheBackendInterface::set() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidate() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateAll() - */ - public function invalidateTags(array $tags) { - // TODO: Implement invalidateTags() method. - } } diff --git a/core/lib/Drupal/Core/Cache/NullCacheTagHandler.php b/core/lib/Drupal/Core/Cache/NullCacheTagHandler.php deleted file mode 100644 index 8fe1cc2..0000000 --- a/core/lib/Drupal/Core/Cache/NullCacheTagHandler.php +++ /dev/null @@ -1,28 +0,0 @@ -invalidators[] = $service; - } - -} diff --git a/core/lib/Drupal/Core/Cache/PhpBackend.php b/core/lib/Drupal/Core/Cache/PhpBackend.php index d4eea88..99a8bc9 100644 --- a/core/lib/Drupal/Core/Cache/PhpBackend.php +++ b/core/lib/Drupal/Core/Cache/PhpBackend.php @@ -36,13 +36,23 @@ class PhpBackend implements CacheBackendInterface { protected $cache = array(); /** + * The cache tags storage. + * + * @var \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface + */ + protected $cacheTagsStorage; + + /** * 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. */ - public function __construct($bin) { + public function __construct($bin, CacheTagsInvalidationStorageInterface $cache_tags_storage) { $this->bin = 'cache_' . $bin; + $this->cacheTagsStorage = $cache_tags_storage; } /** @@ -122,6 +132,12 @@ 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. + $checksum = $this->cacheTagsStorage->checksumTags($cache->tags); + if ($cache->checksum_invalidations != $checksum) { + $cache->valid = FALSE; + } + if (!$allow_invalid && !$cache->valid) { return FALSE; } @@ -133,13 +149,17 @@ protected function prepareItem($cache, $allow_invalid) { * {@inheritdoc} */ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) { - Cache::validateTags($tags); + if ($tags) { + Cache::validateTags($tags); + $this->cacheTagsStorage->onCacheTagsWrite($tags); + } $item = (object) array( 'cid' => $cid, 'data' => $data, 'created' => round(microtime(TRUE), 3), 'expire' => $expire, 'tags' => array_unique($tags), + 'checksum_invalidations' => $this->cacheTagsStorage->checksumTags($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 6102fa8..c0f7096 100644 --- a/core/lib/Drupal/Core/Cache/PhpBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/PhpBackendFactory.php @@ -7,7 +7,24 @@ namespace Drupal\Core\Cache; -class PhpBackendFactory implements CacheFactoryInterface, CacheTagInvalidationInterface { +class PhpBackendFactory implements CacheFactoryInterface { + + /** + * The cache tags storage. + * + * @var \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface + */ + protected $cacheTagsStorage; + + /** + * Constructs a PhpBackendFactory object. + * + * @param \Drupal\Core\Cache\CacheTagsInvalidationStorageInterface $cache_tags_storage + * Cache tags storage. + */ + public function __construct(CacheTagsInvalidationStorageInterface $cache_tags_storage) { + $this->cacheTagsStorage = $cache_tags_storage; + } /** * Gets PhpBackend for the specified cache bin. @@ -19,22 +36,7 @@ class PhpBackendFactory implements CacheFactoryInterface, CacheTagInvalidationIn * The cache backend object for the specified cache bin. */ function get($bin) { - return new PhpBackend($bin); + return new PhpBackend($bin, $this->cacheTagsStorage); } - /** - * Marks cache items with any of the specified tags as invalid. - * - * @param array $tags - * Associative array of tags, in the same format that is passed to - * CacheBackendInterface::set(). - * - * @see \Drupal\Core\Cache\CacheBackendInterface::set() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidate() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateAll() - */ - public function invalidateTags(array $tags) { - // TODO: Implement invalidateTags() method. - } } diff --git a/core/lib/Drupal/Core/Field/FieldStorageDefinitionInterface.php b/core/lib/Drupal/Core/Field/FieldStorageDefinitionInterface.php index 9b0eb65..70206af 100644 --- a/core/lib/Drupal/Core/Field/FieldStorageDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/FieldStorageDefinitionInterface.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Field; use Drupal\Core\Entity\FieldableEntityInterface; +use Drupal\Core\TypedData\DataDefinitionInterface; /** * Defines an interface for entity field storage definitions. @@ -27,7 +28,7 @@ * * @see hook_entity_field_storage_info() */ -interface FieldStorageDefinitionInterface { +interface FieldStorageDefinitionInterface extends DataDefinitionInterface { /** * Value indicating a field accepts an unlimited number of values. diff --git a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php index af823f7..6e93561 100644 --- a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php +++ b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php @@ -48,8 +48,6 @@ public function register(ContainerBuilder $container) { ->addArgument(new Reference('request_stack')); $container ->register('router.dumper', 'Drupal\Core\Routing\NullMatcherDumper'); - $container - ->register('cache_tags', 'Drupal\Core\Cache\NullCacheTagHandler'); // Replace the route builder with an empty implementation. // @todo Convert installer steps into routes; add an installer.routing.yml. diff --git a/core/modules/config/src/Tests/Storage/CachedStorageTest.php b/core/modules/config/src/Tests/Storage/CachedStorageTest.php index 2d4e464..8a71f1f 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_tag_storage')); + ->addArgument(new Reference('cache_tags_storage')); } } diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php index 9ae0fc4..a82f2ba 100644 --- a/core/modules/field/src/Entity/FieldStorageConfig.php +++ b/core/modules/field/src/Entity/FieldStorageConfig.php @@ -755,4 +755,85 @@ public function isDeletable() { return !$this->deleted && !$this->persist_with_no_fields && count($this->getBundles()) == 0; } -} + /** + * Creates a new data definition object. + * + * This method is typically used by + * \Drupal\Core\TypedData\TypedDataManager::createDataDefinition() to build a + * definition object for an arbitrary data type. When the definition class is + * known, it is recommended to directly use the static create() method on that + * class instead; e.g.: + * + * @code + * $map_definition = \Drupal\Core\TypedData\MapDataDefinition::create(); + * @endcode + * + * @param string $data_type + * The data type, for which a data definition should be created. + * + * @throws \InvalidArgumentException + * If an unsupported data type gets passed to the class; e.g., 'string' to a + * definition class handling 'entity:* data types. + * + * @return static + */ + public static function createFromDataType($data_type) { + // TODO: Implement createFromDataType() method. + } + + /** + * Returns the data type of the data. + * + * @return string + * The data type. + */ + public function getDataType() { + // TODO: Implement getDataType() method. + } + + /** + * Returns whether the data is multi-valued, i.e. a list of data items. + * + * This is equivalent to checking whether the data definition implements the + * \Drupal\Core\TypedData\ListDefinitionInterface interface. + * + * @return bool + * Whether the data is multi-valued. + */ + public function isList() { + // TODO: Implement isList() method. + } + + /** + * Determines whether the data is read-only. + * + * @return bool + * Whether the data is read-only. + */ + public function isReadOnly() { + // TODO: Implement isReadOnly() method. + } + + /** + * Determines whether the data value is computed. + * + * For example, data could be computed depending on some other values. + * + * @return bool + * Whether the data value is computed. + */ + public function isComputed() { + // TODO: Implement isComputed() method. + } + + /** + * Returns the class used for creating the typed data object. + * + * If not specified, the default class of the data type will be returned. + * + * @return string + * The class used for creating the typed data object. + */ + public function getClass() { + // TODO: Implement getClass() method. + }} diff --git a/core/modules/locale/src/Tests/LocaleTranslationUiTest.php b/core/modules/locale/src/Tests/LocaleTranslationUiTest.php index 26c929e..774aee2 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_tag_storage')->reset(); + \Drupal::service('cache_tags_storage')->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/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php index 7abd200..f26c5d4 100644 --- a/core/modules/simpletest/src/KernelTestBase.php +++ b/core/modules/simpletest/src/KernelTestBase.php @@ -256,8 +256,7 @@ public function containerBuild(ContainerBuilder $container) { $this->container->setParameter('language.default_values', Language::$defaultValues); $container->register('lock', 'Drupal\Core\Lock\NullLockBackend'); - $container->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory') - ->addTag('cache_tags'); + $container->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory'); $container ->register('config.storage', 'Drupal\Core\Config\DatabaseStorage') diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 679af68..62355a5 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -1148,7 +1148,7 @@ protected function resetAll() { */ protected function refreshVariables() { // Clear the tag cache. - \Drupal::service('cache_tag_storage')->reset(); + \Drupal::service('cache_tags_storage')->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 c10f25a..ad1dc81 100644 --- a/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php +++ b/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php @@ -34,8 +34,7 @@ protected function checkRequirements() { } protected function createCacheBackend($bin) { - $backend = new ApcuBackend($bin, $this->databasePrefix); - \Drupal::service('cache_tags')->addHandler($backend); + $backend = new ApcuBackend($bin, $this->databasePrefix, \Drupal::service('cache_tags_storage')); return $backend; } diff --git a/core/modules/system/src/Tests/Cache/BackendChainUnitTest.php b/core/modules/system/src/Tests/Cache/BackendChainUnitTest.php index 1cbaf49..39b797e 100644 --- a/core/modules/system/src/Tests/Cache/BackendChainUnitTest.php +++ b/core/modules/system/src/Tests/Cache/BackendChainUnitTest.php @@ -26,7 +26,7 @@ protected function createCacheBackend($bin) { ->prependBackend(new MemoryBackend('bar')) ->appendBackend(new MemoryBackend('baz')); - \Drupal::service('cache_tags')->addHandler($chain); + \Drupal::service('cache_tags_invalidator')->addInvalidator($chain); return $chain; } diff --git a/core/modules/system/src/Tests/Cache/ChainedFastBackendUnitTest.php b/core/modules/system/src/Tests/Cache/ChainedFastBackendUnitTest.php index 32488a6..0cf3883 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($this->container->get('database'), $bin); - $fast_backend = new PhpBackend($bin); + $consistent_backend = new DatabaseBackend($this->container->get('database'), \Drupal::service('cache_tags_storage'), $bin); + $fast_backend = new PhpBackend($bin, \Drupal::service('cache_tags_storage')); 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 518383b..b458996 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_tag_storage'), $bin); + return new DatabaseBackend($this->container->get('database'), $this->container->get('cache_tags_storage'), $bin); } } diff --git a/core/modules/system/src/Tests/Cache/MemoryBackendUnitTest.php b/core/modules/system/src/Tests/Cache/MemoryBackendUnitTest.php index 3a99482..b5b6916 100644 --- a/core/modules/system/src/Tests/Cache/MemoryBackendUnitTest.php +++ b/core/modules/system/src/Tests/Cache/MemoryBackendUnitTest.php @@ -24,7 +24,7 @@ class MemoryBackendUnitTest extends GenericCacheBackendUnitTestBase { */ protected function createCacheBackend($bin) { $backend = new MemoryBackend($bin); - \Drupal::service('cache_tags')->addHandler($backend); + \Drupal::service('cache_tags_invalidator')->addInvalidator($backend); return $backend; } } diff --git a/core/modules/system/src/Tests/Cache/PhpBackendUnitTest.php b/core/modules/system/src/Tests/Cache/PhpBackendUnitTest.php index 01b58ca..e19cf35 100644 --- a/core/modules/system/src/Tests/Cache/PhpBackendUnitTest.php +++ b/core/modules/system/src/Tests/Cache/PhpBackendUnitTest.php @@ -23,8 +23,7 @@ class PhpBackendUnitTest extends GenericCacheBackendUnitTestBase { * A new MemoryBackend object. */ protected function createCacheBackend($bin) { - $backend = new PhpBackend($bin); - \Drupal::service('cache_tags')->addHandler($backend); + $backend = new PhpBackend($bin, \Drupal::service('cache_tags_storage')); return $backend; } diff --git a/core/modules/views/tests/src/Unit/ViewsDataTest.php b/core/modules/views/tests/src/Unit/ViewsDataTest.php index 18424c9..d3e2a07 100644 --- a/core/modules/views/tests/src/Unit/ViewsDataTest.php +++ b/core/modules/views/tests/src/Unit/ViewsDataTest.php @@ -26,11 +26,11 @@ class ViewsDataTest extends UnitTestCase { protected $cacheBackend; /** - * The mocked cache tag handler. + * The mocked cache tag invalidator. * - * @var \Drupal\Core\Cache\CacheTagHandlerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $cacheTagHandler; + protected $cacheTagsInvalidator; /** * The mocked module handler. @@ -64,9 +64,9 @@ class ViewsDataTest extends UnitTestCase { * {@inheritdoc} */ protected function setUp() { - $this->cacheTagHandler = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); + $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface'); $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); - $this->getContainerWithCacheBins($this->cacheTagHandler); + $this->getContainerWithCacheBins($this->cacheTagsInvalidator); $configs = array(); $configs['views.settings']['skip_cache'] = FALSE; @@ -258,7 +258,7 @@ public function testFullAndTableGetCache() { $this->cacheBackend->expects($this->at(3)) ->method('set') ->with("views_data:$random_table_name:en", array()); - $this->cacheTagHandler->expects($this->once()) + $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(['views_data']); $this->cacheBackend->expects($this->at(4)) diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php index 462a743..cf3962e 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php @@ -24,11 +24,11 @@ class CacheCollectorTest extends UnitTestCase { protected $cacheBackend; /** - * The cache tag handler. + * The cache tag invalidator. * * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $cacheTagHandler; + protected $cacheTagsInvalidator; /** * The lock backend that should be used. @@ -56,12 +56,12 @@ class CacheCollectorTest extends UnitTestCase { */ protected function setUp() { $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); - $this->cacheTagHandler = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); + $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface'); $this->lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface'); $this->cid = $this->randomMachineName(); $this->collector = new CacheCollectorHelper($this->cid, $this->cacheBackend, $this->lock); - $this->getContainerWithCacheBins($this->cacheTagHandler); + $this->getContainerWithCacheBins($this->cacheTagsInvalidator); } @@ -384,7 +384,7 @@ public function testUpdateCacheClear() { $this->cacheBackend->expects($this->once()) ->method('delete') ->with($this->cid); - $this->cacheTagHandler->expects($this->never()) + $this->cacheTagsInvalidator->expects($this->never()) ->method('invalidateTags'); $this->collector->clear(); $this->assertEquals($value, $this->collector->get($key)); @@ -411,7 +411,7 @@ public function testUpdateCacheClearTags() { // Clear the collected cache using the tags, should call it again. $this->cacheBackend->expects($this->never()) ->method('delete'); - $this->cacheTagHandler->expects($this->once()) + $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with($tags); $this->collector->clear(); diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php new file mode 100644 index 0000000..80da113 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php @@ -0,0 +1,31 @@ +invalidateTags(['node' => [2, 3, 5, 8, 13]]); + } + +} diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheTest.php index a01fbf5..ea30f1a 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheTest.php @@ -117,14 +117,4 @@ public function testBuildTags($prefix, array $suffixes, array $expected) { $this->assertEquals($expected, Cache::buildTags($prefix, $suffixes)); } - /** - * @covers ::invalidateTags - * - * @expectedException \LogicException - * @expectedExceptionMessage Cache tags must be strings, array given. - */ - public function testInvalidateTags() { - Cache::invalidateTags(['node' => [2, 3, 5, 8, 13]]); - } - } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php index 02ce8b5..8405d8a 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -79,9 +79,9 @@ class ConfigEntityBaseUnitTest extends UnitTestCase { /** * The mocked cache backend. * - * @var \Drupal\Core\Cache\cacheTagHandlerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $cacheTagHandler; + protected $cacheTagsInvalidator; /** * The mocked typed config manager. @@ -121,7 +121,7 @@ protected function setUp() { ->with('en') ->will($this->returnValue(new Language(array('id' => 'en')))); - $this->cacheTagHandler = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); + $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface'); $this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface'); @@ -129,7 +129,7 @@ protected function setUp() { $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); $container->set('language_manager', $this->languageManager); - $container->set('cache_tags', $this->cacheTagHandler); + $container->set('cache_tags_invalidator', $this->cacheTagsInvalidator); $container->set('config.typed', $this->typedConfigManager); \Drupal::setContainer($container); @@ -360,7 +360,7 @@ public function testEnable() { * @depends testSetStatus */ public function testDisable() { - $this->cacheTagHandler->expects($this->once()) + $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(array($this->entityTypeId . ':' . $this->id)); diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index bf7ca84..d9edc78 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -85,9 +85,9 @@ class ConfigEntityStorageTest extends UnitTestCase { /** * The mocked cache backend. * - * @var \Drupal\Core\Cache\cacheTagHandlerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $cacheTagHandler; + protected $cacheTagsInvalidator; /** * The mocked typed config manager. @@ -153,7 +153,7 @@ protected function setUp() { ->with('test_entity_type') ->will($this->returnValue($this->entityType)); - $this->cacheTagHandler = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); + $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface'); $this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface'); $this->typedConfigManager->expects($this->any()) @@ -162,7 +162,7 @@ protected function setUp() { $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('config.typed', $this->typedConfigManager); - $container->set('cache_tags', $this->cacheTagHandler); + $container->set('cache_tags_invalidator', $this->cacheTagsInvalidator); \Drupal::setContainer($container); } @@ -172,7 +172,7 @@ protected function setUp() { * @covers ::doCreate */ public function testCreateWithPredefinedUuid() { - $this->cacheTagHandler->expects($this->never()) + $this->cacheTagsInvalidator->expects($this->never()) ->method('invalidateTags'); $this->moduleHandler->expects($this->at(0)) @@ -197,7 +197,7 @@ public function testCreateWithPredefinedUuid() { * @return \Drupal\Core\Entity\EntityInterface */ public function testCreate() { - $this->cacheTagHandler->expects($this->never()) + $this->cacheTagsInvalidator->expects($this->never()) ->method('invalidateTags'); $this->moduleHandler->expects($this->at(0)) @@ -239,7 +239,7 @@ public function testSaveInsert(EntityInterface $entity) { $config_object->expects($this->once()) ->method('save'); - $this->cacheTagHandler->expects($this->once()) + $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(array( $this->entityTypeId . '_list', // List cache tag. @@ -298,7 +298,7 @@ public function testSaveUpdate(EntityInterface $entity) { $config_object->expects($this->once()) ->method('save'); - $this->cacheTagHandler->expects($this->once()) + $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(array( $this->entityTypeId . ':foo', // Own cache tag. @@ -358,7 +358,7 @@ public function testSaveRename(ConfigEntityInterface $entity) { $config_object->expects($this->once()) ->method('save'); - $this->cacheTagHandler->expects($this->once()) + $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(array( $this->entityTypeId .':bar', // Own cache tag. @@ -402,7 +402,7 @@ public function testSaveRename(ConfigEntityInterface $entity) { * @expectedExceptionMessage The entity does not have an ID. */ public function testSaveInvalid() { - $this->cacheTagHandler->expects($this->never()) + $this->cacheTagsInvalidator->expects($this->never()) ->method('invalidateTags'); $entity = $this->getMockEntity(); @@ -427,7 +427,7 @@ public function testSaveDuplicate() { $config_object->expects($this->never()) ->method('save'); - $this->cacheTagHandler->expects($this->never()) + $this->cacheTagsInvalidator->expects($this->never()) ->method('invalidateTags'); $this->configFactory->expects($this->once()) @@ -458,7 +458,7 @@ public function testSaveMismatch() { $config_object->expects($this->never()) ->method('save'); - $this->cacheTagHandler->expects($this->never()) + $this->cacheTagsInvalidator->expects($this->never()) ->method('invalidateTags'); $this->configFactory->expects($this->once()) @@ -491,7 +491,7 @@ public function testSaveNoMismatch() { $config_object->expects($this->once()) ->method('save'); - $this->cacheTagHandler->expects($this->once()) + $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(array( $this->entityTypeId . '_list', // List cache tag. @@ -541,7 +541,7 @@ public function testSaveChangedUuid() { array('id', 'foo'), ))); - $this->cacheTagHandler->expects($this->never()) + $this->cacheTagsInvalidator->expects($this->never()) ->method('invalidateTags'); $this->configFactory->expects($this->at(1)) @@ -698,7 +698,7 @@ public function testLoadRevision() { * @covers ::deleteRevision */ public function testDeleteRevision() { - $this->cacheTagHandler->expects($this->never()) + $this->cacheTagsInvalidator->expects($this->never()) ->method('invalidateTags'); $this->assertSame(NULL, $this->entityStorage->deleteRevision(1)); @@ -724,7 +724,7 @@ public function testDelete() { $config_map[] = array("the_config_prefix.$id", $config_object); } - $this->cacheTagHandler->expects($this->once()) + $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(array( $this->entityTypeId . ':bar', // Own cache tag. @@ -774,7 +774,7 @@ public function testDeleteNothing() { $this->configFactory->expects($this->never()) ->method('get'); - $this->cacheTagHandler->expects($this->never()) + $this->cacheTagsInvalidator->expects($this->never()) ->method('invalidateTags'); $this->entityStorage->delete(array()); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index 4951648..4873602 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -66,11 +66,11 @@ class EntityManagerTest extends UnitTestCase { protected $cacheBackend; /** - * The cache tag handler. + * The cache tag invalidator. * - * @var \Drupal\Core\Cache\CacheTagHandlerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $cacheTagHandler; + protected $cacheTagsInvalidator; /** * The language manager. @@ -127,7 +127,7 @@ protected function setUp() { ->will($this->returnValue(array())); $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); - $this->cacheTagHandler = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); + $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface'); $language = $this->getMock('Drupal\Core\Language\LanguageInterface'); $language->expects($this->any()) @@ -147,7 +147,7 @@ protected function setUp() { $this->formBuilder = $this->getMock('Drupal\Core\Form\FormBuilderInterface'); $this->controllerResolver = $this->getClassResolverStub(); - $this->container = $this->getContainerWithCacheBins($this->cacheTagHandler); + $this->container = $this->getContainerWithCacheBins($this->cacheTagsInvalidator); $this->discovery = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface'); @@ -201,13 +201,13 @@ protected function setUpEntityManager($definitions = array()) { */ public function testClearCachedDefinitions() { $this->setUpEntityManager(); - $this->cacheTagHandler->expects($this->at(0)) + $this->cacheTagsInvalidator->expects($this->at(0)) ->method('invalidateTags') ->with(array('entity_types')); - $this->cacheTagHandler->expects($this->at(1)) + $this->cacheTagsInvalidator->expects($this->at(1)) ->method('invalidateTags') ->with(array('entity_bundles')); - $this->cacheTagHandler->expects($this->at(2)) + $this->cacheTagsInvalidator->expects($this->at(2)) ->method('invalidateTags') ->with(array('entity_field_info')); @@ -779,7 +779,7 @@ protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $f */ public function testClearCachedFieldDefinitions() { $this->setUpEntityManager(); - $this->cacheTagHandler->expects($this->once()) + $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(array('entity_field_info')); $this->typedDataManager->expects($this->once()) @@ -795,7 +795,7 @@ public function testClearCachedFieldDefinitions() { */ public function testClearCachedBundles() { $this->setUpEntityManager(); - $this->cacheTagHandler->expects($this->once()) + $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(array('entity_bundles')); @@ -881,13 +881,13 @@ public function testGetAllBundleInfo() { $this->cacheBackend->expects($this->at(3)) ->method('set') ->with("entity_bundle_info:en"); - $this->cacheTagHandler->expects($this->at(0)) + $this->cacheTagsInvalidator->expects($this->at(0)) ->method('invalidateTags') ->with(array('entity_types')); - $this->cacheTagHandler->expects($this->at(1)) + $this->cacheTagsInvalidator->expects($this->at(1)) ->method('invalidateTags') ->with(array('entity_bundles')); - $this->cacheTagHandler->expects($this->at(2)) + $this->cacheTagsInvalidator->expects($this->at(2)) ->method('invalidateTags') ->with(array('entity_field_info')); $this->cacheBackend->expects($this->at(4)) diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php index c512fb1..9eb4660 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php @@ -75,9 +75,9 @@ class EntityUnitTest extends UnitTestCase { /** * The mocked cache backend. * - * @var \Drupal\Core\Cache\cacheTagHandlerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $cacheTagHandler; + protected $cacheTagsInvalidator; /** * The entity values. @@ -116,13 +116,13 @@ protected function setUp() { ->with('en') ->will($this->returnValue(new Language(array('id' => 'en')))); - $this->cacheTagHandler = $this->getMock('Drupal\Core\Cache\CacheTagHandler'); + $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidator'); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); $container->set('language_manager', $this->languageManager); - $container->set('cache_tags', $this->cacheTagHandler); + $container->set('cache_tags_invalidator', $this->cacheTagsInvalidator); \Drupal::setContainer($container); $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Entity\Entity', array($this->values, $this->entityTypeId)); @@ -392,12 +392,12 @@ public function testPreSave() { * @covers ::postSave */ public function testPostSave() { - $this->cacheTagHandler->expects($this->at(0)) + $this->cacheTagsInvalidator->expects($this->at(0)) ->method('invalidateTags') ->with(array( $this->entityTypeId . '_list', // List cache tag. )); - $this->cacheTagHandler->expects($this->at(1)) + $this->cacheTagsInvalidator->expects($this->at(1)) ->method('invalidateTags') ->with(array( $this->entityTypeId . ':' . $this->values['id'], // Own cache tag. @@ -449,7 +449,7 @@ public function testPreDelete() { * @covers ::postDelete */ public function testPostDelete() { - $this->cacheTagHandler->expects($this->once()) + $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(array( $this->entityTypeId . ':' . $this->values['id'], diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php index a79b9c3..fb10b99 100644 --- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -70,9 +70,9 @@ class KeyValueEntityStorageTest extends UnitTestCase { /** * The mocked cache backend. * - * @var \Drupal\Core\Cache\cacheTagHandlerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $cacheTagHandler; + protected $cacheTagsInvalidator; /** * {@inheritdoc} @@ -110,7 +110,7 @@ protected function setUpKeyValueEntityStorage($uuid_key = 'uuid') { ->with('test_entity_type') ->will($this->returnValue($this->entityType)); - $this->cacheTagHandler = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); + $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface'); $this->keyValueStore = $this->getMock('Drupal\Core\KeyValueStore\KeyValueStoreInterface'); $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); @@ -130,7 +130,7 @@ protected function setUpKeyValueEntityStorage($uuid_key = 'uuid') { $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('language_manager', $this->languageManager); - $container->set('cache_tags', $this->cacheTagHandler); + $container->set('cache_tags_invalidator', $this->cacheTagsInvalidator); \Drupal::setContainer($container); } diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php index 89ed10c..f8913db 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php @@ -121,7 +121,7 @@ protected function setUp() { $logger = $this->getMock('Psr\Log\LoggerInterface'); $this->themeHandler = new TestThemeHandler($this->root, $this->configFactory, $this->moduleHandler, $this->state, $this->infoParser, $logger, $this->cssCollectionOptimizer, $this->configInstaller, $this->configManager, $this->routeBuilderIndicator, $this->extensionDiscovery); - $cache_backend = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); + $cache_backend = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface'); $this->getContainerWithCacheBins($cache_backend); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 585a194..2cd5f30 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -191,8 +191,8 @@ public function testDefaultPluginManagerWithFilledCache() { public function testCacheClearWithTags() { $cid = $this->randomMachineName(); $cache_backend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); - $cache_tag_handler = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); - $cache_tag_handler + $cache_tags_invalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface'); + $cache_tags_invalidator ->expects($this->once()) ->method('invalidateTags') ->with(array('tag')); @@ -200,7 +200,7 @@ public function testCacheClearWithTags() { ->expects($this->never()) ->method('deleteMultiple'); - $this->getContainerWithCacheBins($cache_tag_handler); + $this->getContainerWithCacheBins($cache_tags_invalidator); $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, NULL, NULL, '\Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface'); $plugin_manager->setCacheBackend($cache_backend, $cid, array('tag')); diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index 268dadd..015b3bb 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -8,7 +8,7 @@ namespace Drupal\Tests; use Drupal\Component\Utility\Random; -use Drupal\Core\Cache\CacheTagHandlerInterface; +use Drupal\Core\Cache\CacheTagsInvalidatorInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; /** @@ -198,17 +198,17 @@ public function getStringTranslationStub() { /** * Sets up a container with cache bins. * - * @param \Drupal\Core\Cache\CacheTagHandlerInterface $cache_tags_handler + * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_handler * The cache backend to set up. * * @return \Symfony\Component\DependencyInjection\ContainerInterface|\PHPUnit_Framework_MockObject_MockObject * The container with the cache bins set up. */ - protected function getContainerWithCacheBins(CacheTagHandlerInterface $cache_tags_handler) { + protected function getContainerWithCacheBins(CacheTagsInvalidatorInterface $cache_tags_handler) { $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); $container->expects($this->any()) ->method('get') - ->with('cache_tags') + ->with('cache_tags_invalidator') ->will($this->returnValue($cache_tags_handler)); \Drupal::setContainer($container); diff --git a/sites/development.services.yml b/sites/development.services.yml index 75c5f44..cc21211 100644 --- a/sites/development.services.yml +++ b/sites/development.services.yml @@ -5,9 +5,5 @@ services: cache.backend.memory: class: Drupal\Core\Cache\MemoryBackendFactory - tags: - - { name: cache_tags } cache.backend.null: class: Drupal\Core\Cache\NullBackendFactory - tags: - - { name: cache_tags }