diff --git a/core/lib/Drupal/Core/Cache/ChainedFastBackend.php b/core/lib/Drupal/Core/Cache/ChainedFastBackend.php index 9f6be9d8ab8167194287712cb335a4f3b692b35f..7426aba15133b09c636f35854c7572c87ef6acb8 100644 --- a/core/lib/Drupal/Core/Cache/ChainedFastBackend.php +++ b/core/lib/Drupal/Core/Cache/ChainedFastBackend.php @@ -12,7 +12,9 @@ * item. The fast backend will also typically be inconsistent (will only see * changes from one web node). The slower backend will be something like Mysql, * Memcached or Redis, and will be used by all web nodes, thus making it - * consistent, but also require a network round trip for each cache get. + * consistent, but also require a network round trip for each cache get. The + * fast backend must however also use a consistent cache tag invalidation, for + * example by using the cache tag checksum API. * * In addition to being useful for sites running on multiple web nodes, this * backend can also be useful for sites running on a single web node where the @@ -164,9 +166,7 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) { if ($cids) { foreach ($this->consistentBackend->getMultiple($cids, $allow_invalid) as $item) { $cache[$item->cid] = $item; - // Don't write the cache tags to the fast backend as any cache tag - // invalidation results in an invalidation of the whole fast backend. - $this->fastBackend->set($item->cid, $item->data, $item->expire); + $this->fastBackend->set($item->cid, $item->data, $item->expire, $item->tags); } } @@ -179,9 +179,7 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) { public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) { $this->consistentBackend->set($cid, $data, $expire, $tags); $this->markAsOutdated(); - // Don't write the cache tags to the fast backend as any cache tag - // invalidation results in an invalidation of the whole fast backend. - $this->fastBackend->set($cid, $data, $expire); + $this->fastBackend->set($cid, $data, $expire, $tags); } /** @@ -190,11 +188,6 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) { public function setMultiple(array $items) { $this->consistentBackend->setMultiple($items); $this->markAsOutdated(); - // Don't write the cache tags to the fast backend as any cache tag - // invalidation results in an invalidation of the whole fast backend. - foreach ($items as &$item) { - unset($item['tags']); - } $this->fastBackend->setMultiple($items); } @@ -244,7 +237,9 @@ public function invalidateTags(array $tags) { if ($this->consistentBackend instanceof CacheTagsInvalidatorInterface) { $this->consistentBackend->invalidateTags($tags); } - $this->markAsOutdated(); + if ($this->fastBackend instanceof CacheTagsInvalidatorInterface) { + $this->fastBackend->invalidateTags($tags); + } } /**