Problem/Motivation
Cache tags are brilliant when they work well, and can be obtuse and difficult to use when they don't.
In the case of preprocessing nodes, it's quite difficult to find a way to make sure that node cache tags bubble correctly. Consider this use case (seemingly pretty common):
- "Parent" nodes have one "Child" node associated with it.
- The Parent node should render the Parent node, then render the Child node in 'Parent teaser' view mode.
- Themer decides to use a preprocess function to preprocess the Parent node, then get the render array using something like
$view_builder->viewMultiple($child_node, 'parent_teaser')
, then the Twig template prints the teaser. - Content admins complain that when they save updates to the "Child" node, the "Parent" doesn't reflect changes until the entire site's cache is cleared.
Apparently Views'viewRenderable()
method sets all the cache contexts/tags correctly—we need something similar for getting the render arrays for nodes in general...
Proposed resolution
Either document how to add the appropriate cache contexts/tags when rendering a node via preprocess functions, or add functionality to make this easier to do.
Remaining tasks
TBD
User interface changes
N/A
API changes
TBD
Data model changes
N/A