diff --git a/core/lib/Drupal/Core/Cache/CacheTagBackendBase.php b/core/lib/Drupal/Core/Cache/CacheTagBackendBase.php index 23b007d..4e2c190 100644 --- a/core/lib/Drupal/Core/Cache/CacheTagBackendBase.php +++ b/core/lib/Drupal/Core/Cache/CacheTagBackendBase.php @@ -13,13 +13,7 @@ abstract class CacheTagBackendBase implements CacheTagBackendInterface { /** - * 'Flattens' a tags array into an array of strings. - * - * @param array $tags - * Associative array of tags to flatten. - * - * @return array - * An indexed array of flattened tag identifiers. + * {@inheritdoc} */ public function flattenTags(array $tags) { if (isset($tags[0])) { @@ -39,24 +33,4 @@ public function flattenTags(array $tags) { } return $flat_tags; } - - /** - * Raises an array of 'flattened' tags (inverse function to flattenTags()). - * - * @param array $tags - * Associative array of flat tags to raise. - * - * @return array - * An array of raised tags. - */ - public function raiseTags(array $flat_tags) { - $tags = array(); - foreach ($flat_tags as $tag) { - list($key, $value) = explode(':', $tag); - $tags[$key] = $value; - } - - return $tags; - } - } diff --git a/core/lib/Drupal/Core/Cache/CacheTagBackendInterface.php b/core/lib/Drupal/Core/Cache/CacheTagBackendInterface.php index 7a4a629..6e224a1 100644 --- a/core/lib/Drupal/Core/Cache/CacheTagBackendInterface.php +++ b/core/lib/Drupal/Core/Cache/CacheTagBackendInterface.php @@ -35,6 +35,17 @@ public function deleteTags(array $tags); public function invalidateTags(array $tags); /** + * 'Flattens' a tags array into an array of strings. + * + * @param array $tags + * Associative array of tags to flatten. + * + * @return array + * An indexed array of flattened tag identifiers. + */ + public function flattenTags(array $tags); + + /** * Returns the sum total of validations for a given set of tags. * * @param array $tags diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackend.php b/core/lib/Drupal/Core/Cache/DatabaseBackend.php index 2b836fa..a1d4f50 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseBackend.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php @@ -117,7 +117,7 @@ protected function prepareItem($cache, $allow_invalid) { return FALSE; } - $cache->tags = $cache->tags ? $this->cacheTag->raiseTags(explode(' ', $cache->tags)) : array(); + $cache->tags = $cache->tags ? explode(' ', $cache->tags) : array(); // Check expire time. $cache->valid = $time_valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME; @@ -171,8 +171,8 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array * Actually set the cache. */ protected function doSet($cid, $data, $expire, $tags) { - $checksum = $this->cacheTag->checksumTags($tags, TRUE); $flat_tags = $this->cacheTag->flattenTags($tags); + $checksum = $this->cacheTag->checksumTags($flat_tags, TRUE); $fields = array( 'serialized' => 0, 'created' => REQUEST_TIME, diff --git a/core/lib/Drupal/Core/Cache/DatabaseTagBackend.php b/core/lib/Drupal/Core/Cache/DatabaseTagBackend.php index 7fe2225..e406b44 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseTagBackend.php +++ b/core/lib/Drupal/Core/Cache/DatabaseTagBackend.php @@ -81,14 +81,13 @@ public function deleteTags(array $tags) { * {@inheritdoc} */ public function checksumTags(array $tags, $set_context) { - $flat_tags = $this->flattenTags($tags); $tag_cache = &drupal_static('Drupal\Core\Cache\CacheTagBackendInterface::tagCache', array()); if ($set_context) { $deleted_tags = &drupal_static('Drupal\Core\Cache\DatabaseTagBackend::deletedTags', array()); // Remove tags that were already deleted during this request from the static // cache so that another deletion for them will be correctly updated. - foreach ($flat_tags as $tag) { + foreach ($tags as $tag) { if (isset($deleted_tags[$tag])) { unset($deleted_tags[$tag]); } @@ -100,7 +99,7 @@ public function checksumTags(array $tags, $set_context) { 'deletions' => 0, ); - $query_tags = array_diff($flat_tags, array_keys($tag_cache)); + $query_tags = array_diff($tags, array_keys($tag_cache)); if ($query_tags) { $db_tags = $this->connection->query('SELECT tag, invalidations, deletions FROM {cache_tags} WHERE tag IN (:tags)', array(':tags' => $query_tags))->fetchAllAssoc('tag', \PDO::FETCH_ASSOC); $tag_cache += $db_tags; @@ -109,7 +108,7 @@ public function checksumTags(array $tags, $set_context) { $tag_cache += array_fill_keys(array_diff($query_tags, array_keys($db_tags)), $checksum); } - foreach ($flat_tags as $tag) { + foreach ($tags as $tag) { $checksum['invalidations'] += $tag_cache[$tag]['invalidations']; $checksum['deletions'] += $tag_cache[$tag]['deletions']; } diff --git a/core/lib/Drupal/Core/Cache/MemoryBackend.php b/core/lib/Drupal/Core/Cache/MemoryBackend.php index 9d636f5..7783f44 100644 --- a/core/lib/Drupal/Core/Cache/MemoryBackend.php +++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php @@ -95,7 +95,6 @@ protected function prepareItem($cache, $allow_invalid) { // Check expire time. $cache->valid = $time_valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME; - $cache->tags = $this->cacheTag->raiseTags($cache->tags); $this->cacheTag->prepareGet($cache); if ($cache->deleted) { @@ -118,13 +117,14 @@ protected function prepareItem($cache, $allow_invalid) { * Implements Drupal\Core\Cache\CacheBackendInterface::set(). */ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) { - $checksum = $this->cacheTag->checksumTags($tags, TRUE); + $flat_tags = $this->cacheTag->flattenTags($tags); + $checksum = $this->cacheTag->checksumTags($flat_tags, TRUE); $this->cache[$cid] = (object) array( 'cid' => $cid, 'data' => $data, 'created' => REQUEST_TIME, 'expire' => $expire, - 'tags' => $this->flattenTags($tags), + 'tags' => $flat_tags, 'checksum_invalidations' => $checksum['invalidations'], 'checksum_deletions' => $checksum['deletions'], ); diff --git a/core/lib/Drupal/Core/Cache/MemoryTagBackend.php b/core/lib/Drupal/Core/Cache/MemoryTagBackend.php index d7dba4f..4920b05 100644 --- a/core/lib/Drupal/Core/Cache/MemoryTagBackend.php +++ b/core/lib/Drupal/Core/Cache/MemoryTagBackend.php @@ -57,13 +57,12 @@ public function deleteTags(array $tags) { * {@inheritdoc} */ public function checksumTags(array $tags, $set_context) { - $flat_tags = $this->flattenTags($tags); $checksum = array( 'invalidations' => 0, 'deletions' => 0, ); - foreach ($flat_tags as $tag) { + foreach ($tags as $tag) { $this->ensureItem($tag); $checksum['invalidations'] += $this->storage[$tag]['invalidations']; $checksum['deletions'] += $this->storage[$tag]['deletions']; diff --git a/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php index 99e8de7..4654baf 100644 --- a/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php +++ b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php @@ -8,6 +8,7 @@ namespace Drupal\hal\Tests; use Drupal\Core\Cache\MemoryBackend; +use Drupal\Core\Cache\MemoryTagBackend; use Drupal\Core\Language\Language; use Drupal\hal\Encoder\JsonEncoder; use Drupal\hal\Normalizer\EntityNormalizer; @@ -120,7 +121,7 @@ function setUp() { 'bundle' => 'entity_test', ))->save(); - $link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend('cache')), new RelationLinkManager(new MemoryBackend('cache'))); + $link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend(new MemoryTagBackend(), 'cache')), new RelationLinkManager(new MemoryBackend(new MemoryTagBackend(), 'cache'))); // Set up the mock serializer. $normalizers = array( diff --git a/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php b/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php index 55a0114..e4bde51 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php @@ -8,6 +8,7 @@ namespace Drupal\system\Tests\Path; use Drupal\Core\Cache\MemoryCounterBackend; +use Drupal\Core\Cache\MemoryTagBackend; use Drupal\Core\Path\Path; use Drupal\Core\Database\Database; use Drupal\Core\Path\AliasManager; @@ -165,7 +166,7 @@ function testWhitelist() { $connection = Database::getConnection(); $this->fixtures->createTables($connection); - $memoryCounterBackend = new MemoryCounterBackend('cache'); + $memoryCounterBackend = new MemoryCounterBackend(new MemoryTagBackend(), 'cache'); // Create AliasManager and Path object. $whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend, $this->container->get('lock'), $this->container->get('state'), $connection);