By wim leers on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Issue links:
Description:
Before this patch landed, Drupal 8 had the following DX problems with cache tags:
- Any code does
['foo' => TRUE'], then any other code no longer can do['foo' => [35 => 35]]. We've had core bugs because of that. - If the
$tagsargument ofdrupal_merge_cache_tags()has something like['entity_test' => [0 => '1']]and the$otherargument 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', ); - 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 usingCache::invalidateTags()orCache::deleteTags(). i.e.: always. Verified with test coverage. - Cache tag merging should now be done using
Cache::mergeTags()rather than withNestedArray,array_merge()ordrupal_merge_cache_tags(). 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).HtmlViewSubscriber::convertCacheTagsToHeader()andHtmlViewSubscriber::convertHeaderToCacheTags()have been removed.
API changes
Retroactively updated the following change records:
Impacts:
Module developers