Score:1

View won't update unless caches are cleared

co flag

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.

cn flag
Do you have anything like Varnish, Redis, some kind of CDN, etc.? Sometimes there's another cache out there somewhere.
in flag
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?
co flag
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).
co flag
@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).
Score:2
cn flag

@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']);
sonfd avatar
in flag
You can also invalidate with the [_cache_tags.invalidator_](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Cache%21CacheTagsInvalidator.php/function/CacheTagsInvalidator%3A%3AinvalidateTags/8.2.x) service (what `Cache::invalidateTags()` calls internally) like: `\Drupal::service('cache_tags.invalidator') ->invalidateTags($tags);`
co flag
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).
4uk4 avatar
cn flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.