2

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?

1 Answer 1

4

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.

3
  • 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
    Commented Apr 22, 2017 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? Commented Apr 23, 2017 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.
    – 4uk4
    Commented Apr 23, 2017 at 12:57

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.