Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Cache/Cache.php \Drupal\Core\Cache\Cache::mergeTags()
  2. 9 core/lib/Drupal/Core/Cache/Cache.php \Drupal\Core\Cache\Cache::mergeTags()

Merges arrays of cache tags and removes duplicates.

The cache tags array is returned in a format that is valid for \Drupal\Core\Cache\CacheBackendInterface::set().

When caching elements, it is necessary to collect all cache tags into a single array, from both the element itself and all child elements. This allows items to be invalidated based on all tags attached to the content they're constituted from.

Parameters

string[] ...: Cache tags arrays to merge.

Return value

string[] The merged array of cache tags.

53 calls to Cache::mergeTags()
AssertPageCacheContextsAndTagsTrait::assertCacheTags in core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php
Ensures that some cache tags are present in the current response.
BlockContentCacheTagsTest::testBlock in core/modules/block_content/tests/src/Functional/BlockContentCacheTagsTest.php
Tests that the block is cached with the correct contexts and tags.
BlockViewBuilder::viewMultiple in core/modules/block/src/BlockViewBuilder.php
Builds the render array for the provided entities.
BlockViewBuilderTest::assertBlockRenderedWithExpectedCacheability in core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php
Asserts that a block is built/rendered/cached with expected cacheability.
BlockViewBuilderTest::testBlockViewBuilderBuildAlter in core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php
Tests block build altering.

... See full list

File

core/lib/Drupal/Core/Cache/Cache.php, line 52

Class

Cache
Helper methods for cache.

Namespace

Drupal\Core\Cache

Code

public static function mergeTags(array ...$cache_tags) {
  $cache_tags = array_unique(array_merge(...$cache_tags));
  assert(Inspector::assertAllStrings($cache_tags), 'Cache tags must be valid strings');
  return $cache_tags;
}