By wim leers on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Introduced in version:
8.0.0-BETA10
Description:
Render arrays whose contents depend on access results, entities or config should associate the cacheability metadata of the objects they depend upon. Thanks to that, any pages containing those rendered render arrays will be refreshed automatically whenever the entity is modified, updated config is deployed, or the access result becomes different.
But, until now, that was painful. That's why we added the RendererInterface::addDependency(array &$build, $dependency) method, which makes doing that trivial.
- Before
-
$build['#cache']['tags'] = Cache::mergeTags(isset($build['#cache']['tags']) ? $build['#cache']['tags'] : [], $config->getCacheTags()); - After
-
$this->renderer->addDependency($build, $config); - Important!
- Dependencies that are passed to this method that don't implement
CacheableDependencyInterfaceare assumed to not be cacheable, and thus causemax-age = 0to be set.
Note: this also mean when more cacheability metadata is added to render arrays, that'd work automatically, no code changes necessary. That's very, very important.
Impacts:
Module developers