In Drupal 7 we could clear a cached URL with the following.

$url = url('<front>',  array('absolute' => TRUE));
cache_clear_all($url, 'cache_page');

What's the equivalent in Drupal 8?


There is no equivalent in D8. What would be the closest to this is to assign a custom cache tag to the page and then invalidate it. See https://www.drupal.org/docs/8/api/cache-api/cache-tags.

But normally you don't need to invalidate cache tags in custom code. If you set the correct cache metadata this should happen automatically.

  • 2
    You could theoretically do it, but there's the internal page cache and the dynamic page cache, which might hold many variations, so it quickly gets complicated. Cache tag is the way to go. @JamesShields, explain your use case and there might be a more specific answer – Berdir Apr 22 '17 at 8:19
  • Thanks for the explanation. My use case is: Form A writes data to table. Page B reads from table and displays. How do I ensure Page B will be refreshed when Form A has added to table? – James Shields Apr 23 '17 at 8:04
  • If Form A uses the entity or configuration api to write data to the table, then you include the cache tag from the entity/configuration in the page and the invalidation takes place automatically. When you use a table outside of Drupal, then you assign a custom cache tag to the page or better to all page elements that include the data and you have to program the invalidation of the custom cache tag on all CRUD operations on that table. See the linked documentation. – 4k4 Apr 23 '17 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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