Change record status: 
Project: 
Introduced in branch: 
8.0.x
Description: 

Before this patch landed, Drupal 8 had the following DX problems with cache tags:

  1. Any code does ['foo' => TRUE'], then any other code no longer can do ['foo' => [35 => 35]]. We've had core bugs because of that.
  2. If the $tags argument of drupal_merge_cache_tags() has something like ['entity_test' => [0 => '1']] and the $other argument has ['entity_test' => [1 => '1']] then the result will contain the value '1' twice.

Now, we use strings rather than arrays.

Old
$tags = array(
  'my_custom_tag' => TRUE,
  'node' => array(1, 3),
  'user' => array(7),
);
New
$tags = array(
  'my_custom_tag',
  'node:1',
  'node:3',
  'user:7',
);

API changes

  1. Cache tags should be strings. An exception is now thrown when they're not, to improve the DX. This happens when using ::set() or ::setMultiple() on a cache back-end and when using Cache::invalidateTags() or Cache::deleteTags(). i.e.: always. Verified with test coverage.
  2. Cache tag merging should now be done using Cache::mergeTags() rather than with NestedArray, array_merge() or drupal_merge_cache_tags().
  3. Cache::buildTags() is provided for the rare use cases where you manually need to build cache tags (only 3 cases in core, but likely more in contrib).
  4. HtmlViewSubscriber::convertCacheTagsToHeader() and HtmlViewSubscriber::convertHeaderToCacheTags() have been removed.

Retroactively updated the following change records:

  1. https://www.drupal.org/node/1272696
  2. https://www.drupal.org/node/1534648
Impacts: 
Module developers