I am using the paragraphs module with a custom theme I created. I want to figure out how to clear the cache for any page that a specific paragraph appears on. The custom theme is composed of a bunch of templates (i.e. paragraph--paragraph-name.html.twig) and a *.theme file where I preprocess each of the paragraph types.


I don't want to disable the entire site's cache. Can I clear the cache in this file? In this way somehow?

  • 2
    Exactly why do you need to clear/disable the cache there? There's a good chance that there's a better solution for whatever you are trying to do.
    – Berdir
    May 9, 2017 at 21:03
  • I created a special Paragraph to display a dynamic set of results. I grab the query string from the URL in the preprocess hook and perform the node query. When I run a different search the display is still of the previous results. If I clear cache through admin panel and run the search, the new results appear. I change the search again it displays the previous stale results.
    – Ryan H
    May 9, 2017 at 21:17
  • 3
    dynamic but only based on the query argument? Then you most likely want to use a combination of cache contexts for the query URL as well as cache tags to invalidate if nodes are created/saved. I would recommend you go through drupal.org/docs/8/api/render-api/cacheability-of-render-arrays and the child-pages and if you have remaining questions, you can update your question
    – Berdir
    May 9, 2017 at 22:05

1 Answer 1


You probably want to be really heavy handed and use \Drupal::service('page_cache_kill_switch')->trigger();

If you put that in a custom module in hook_entity_view_alter() then you can add a conditional that fires it when your paragraph entity is being built.

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.