I would like to disable the cache of that specific part of the node content. Is it possible?

I'm aware I can disable the cache for the node itself using:

$build['#cache']['max-age'] = 0; // users
\Drupal::service('page_cache_kill_switch')->trigger(); // anon users

But I indeed would need to only deactivate for the body content.

Any ideas?


1 Answer 1


The body is not cached on its own, but as part of cached nodes for logged in users or of cached pages for anonymous users. This is what you have already disabled with the code.

You can check this in the cache metadata. Render elements with cache keys get cached. If there is no cache key, then the cache tags, contexts and max-age are bubbled up and merged until they reach an element that has cache keys. This element is then cached including all merged cache metadata that is nested inside.

That means, that cache metadata you set in the body will have no effect on the body to be cached or not, but change, how elements on higher levels like the node or page are cached. For example a cache tag in the body will be included in the tags of the node and the page and if the tag gets invalidated, the cached node and page will both be invalidated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.