public static function Cache::mergeTags

public static Cache::mergeTags(array $a = [], array $b = [])

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

array $a: Cache tags array to merge.

array $b: Cache tags array to merge.

Return value

string[] The merged array of cache tags.

File

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

Class

Cache
Helper methods for cache.

Namespace

Drupal\Core\Cache

Code

public static function mergeTags(array $a = [], array $b = []) {
  assert('\Drupal\Component\Assertion\Inspector::assertAllStrings($a) && \Drupal\Component\Assertion\Inspector::assertAllStrings($b)', 'Cache tags must be valid strings');

  $cache_tags = array_unique(array_merge($a, $b));
  sort($cache_tags);
  return $cache_tags;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Cache!Cache.php/function/Cache::mergeTags/8.1.x