1

In a Drupal 9 site I've built a view that displays specific content for each day of the month (filtering by a date field).

The view shows the correct content for the admin user but not for anyone else unless the caches are flushed.

I've tried switching off the caching for that view, switching off view caching and switching off all caching on the site but none of that makes any difference.

The only way to make the content update correctly is to click the 'Clear all caches' button every day.

This does not make sense. (I've created this kind of view in the past in Drupal 7 and had no such issue.)

Any help would be greatly appreciated.

4
  • Do you have anything like Varnish, Redis, some kind of CDN, etc.? Sometimes there's another cache out there somewhere. Mar 15, 2022 at 15:37
  • It also depends on the configuration of this view. Is this view pulling data from a Search API index? Is this view rendering in an anonymous context? Is the data being rendered by the view computed from something or uses custom logic to retrieve? Are there twig templates manipulating the rendering of the view data or the view itself?
    – Joseph
    Mar 15, 2022 at 15:58
  • The only CDN I'm aware of is for a Webform elsewhere in the site (although I'm not certain that is using a CDN but Drupal kicks up a mass of errors about CDNs unless you suppress it).
    – Podsnap
    Mar 16, 2022 at 9:15
  • @Joseph The view is pretty basic, Title, Body, Date. Any content is added ahead of time and the view displays one entry (the only entry for that day) by using a filter on the Date field of 'Is equal to' 'now' (which has always worked with Drupal 7).
    – Podsnap
    Mar 16, 2022 at 9:18

1 Answer 1

2

@Patrick Kenny, there is also one built-in. To disable this cache for anonymous users uninstall the module Internal Page Cache. Then all traffic will be served by the Dynamic Page Cache, which can be controlled by the cache metadata you configure in the View.

Another way would be to invalidate the View cache tag in a cron job. The Internal Page Cache has the advantage over external caches like Varnish or CDNs that you don't need PURGE requests, you can invalidate the cache tag directly:

\Drupal\Core\Cache\Cache::invalidateTags(['config:views.view.my_view']);
3
  • 1
    You can also invalidate with the cache_tags.invalidator service (what Cache::invalidateTags() calls internally) like: \Drupal::service('cache_tags.invalidator') ->invalidateTags($tags);
    – sonfd
    Mar 15, 2022 at 16:34
  • I really appreciate all these answers but they all seem insanely technical and complex for something that should be relatively basic functionality (and has worked in the past, very simply, with Drupal 7).
    – Podsnap
    Mar 16, 2022 at 9:20
  • Just uninstall the module. See the module page: "Websites that serve to anonymous users dynamic content will want to disable the Internal Page Cache module.". However, your case is not that dynamic, it changes only once per day. So you could choose the second option and keep the performance gain of this module.
    – 4uk4
    Mar 16, 2022 at 14:28

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.