When I turn on cache debugging, I see a lot of cache tags for render arrays that don’t make sense.

I don’t see an obvious way to remove these cache tags. For example, they don’t seem to appear in the $vars for the render array during a preprocess hook.

Are there ways to remove these cache tags?

  • What about them doesn’t make sense?
    – mona lisa
    Commented May 12 at 13:50
  • The specific case that prompted this question was Group adding things that I didn’t think made sense. But, I presume “how to deal with unwanted cache tags” would just be a general category of problem devs might run into generally. (For this case, I read some old comments on the Drupal slack, and that led me to realizing it was related to access checking and some open issues.)
    – miwayha
    Commented May 12 at 16:26

1 Answer 1


There is no such thing as the "render array" in a preprocess hook. This hook is for preparing the variables printed in the Twig template. You have to look into each variable to find out what might bubble up the cache tags.

The top level of $variables is not part of the rendered content. If it contains cache metadata then only because it was added by previous preprocess hooks. The possibility for this cache metadata outside of a render element is a feature added by Drupal to help themers handle cache metadata without diving too deep into the content of the variables, which they are discouraged from doing because the content of those variables is not an official API. Only this place at the top level of $variables is.

  • I’m sorry if I wasn’t clear. I included preprocess functions in my question as an example of one place that I tried to find an answer, but hit a dead end. I guess what I’m asking is, what are there other places I should look, or am I just stuck with the cache tags that other modules give me?
    – miwayha
    Commented May 12 at 16:31
  • Any code within the page render context can bubble up cache tags anytime. As described the content of the template variables can point to this code but there could be more you only find debugging the entire root render process.
    – 4uk4
    Commented May 12 at 18:35
  • I understand that cache tags bubble. And I understand that it’s important to debug the whole render process. What I’m still not understanding is what I asked in my original question: is it ever possible to remove the cache tags that have already been added to a render array? Or do I always need to change the code such that they are never added in the first place?
    – miwayha
    Commented May 13 at 10:48
  • If you have found the code look first for an alter hook, like hook_form_alter for the build array of forms. If there is no hook then you can try to extend the class and swap it in the service container, plugin manager or router table if it is a service, plugin or controller.
    – 4uk4
    Commented May 13 at 11:02
  • Ah that’s really helpful, thank you! I was hoping to avoid swapping out the services, but it’s good to know that’s likely what’s going to be necessary.
    – miwayha
    Commented May 13 at 11:08

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.