From 723ac9580b5e1d348d9d495a98dc88da48cf2639 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Tue, 16 Dec 2014 18:03:51 +0000 Subject: [PATCH] Issue #2392235 by Berdir: ChainedFastBackend shouldn't write cache tags to the fast cache back-end --- core/lib/Drupal/Core/Cache/ChainedFastBackend.php | 13 +++++++++++-- .../Tests/Cache/GenericCacheBackendUnitTestBase.php | 1 - .../Tests/Core/Cache/ChainedFastBackendTest.php | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/lib/Drupal/Core/Cache/ChainedFastBackend.php b/core/lib/Drupal/Core/Cache/ChainedFastBackend.php index 1523ea2a965..559cff78403 100644 --- a/core/lib/Drupal/Core/Cache/ChainedFastBackend.php +++ b/core/lib/Drupal/Core/Cache/ChainedFastBackend.php @@ -160,7 +160,9 @@ class ChainedFastBackend implements CacheBackendInterface { if ($cids) { foreach ($this->consistentBackend->getMultiple($cids, $allow_invalid) as $item) { $cache[$item->cid] = $item; - $this->fastBackend->set($item->cid, $item->data, $item->expire, $item->tags); + // 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); } } @@ -173,7 +175,9 @@ class ChainedFastBackend implements CacheBackendInterface { public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) { $this->consistentBackend->set($cid, $data, $expire, $tags); $this->markAsOutdated(); - $this->fastBackend->set($cid, $data, $expire, $tags); + // 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); } /** @@ -182,6 +186,11 @@ class ChainedFastBackend implements CacheBackendInterface { 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); } diff --git a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php index 97d7ccd6113..d6f31bfcc28 100644 --- a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php +++ b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php @@ -411,7 +411,6 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase { $this->assertEqual($cached['cid_4']->expire, $future_expiration, 'Cache expiration has been correctly set.'); $this->assertEqual($cached['cid_5']->data, $items['cid_5']['data'], 'New cache item set correctly.'); - $this->assertEqual($cached['cid_5']->tags, array('test:a', 'test:b')); // Calling ::setMultiple() with invalid cache tags. try { diff --git a/core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php b/core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php index 798f37d7d76..c2640f2c56e 100644 --- a/core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php @@ -103,7 +103,7 @@ class ChainedFastBackendTest extends UnitTestCase { // We should get a call to set the cache item on the fast backend. $fast_cache->expects($this->once()) ->method('set') - ->with($cache_item->cid, $cache_item->data, $cache_item->expire, $cache_item->tags); + ->with($cache_item->cid, $cache_item->data, $cache_item->expire); $chained_fast_backend = new ChainedFastBackend( $consistent_cache,