3

A view returns an event, which occurs on the current day, in a block. If there is no current event in the database (empty result), a second view is started, which then outputs events from the past.

It is working, when I am logged in. As long as I am logged in, I see correct results, even in the view preview.

If I look at the next day as anonymous user, I don't see the current event; the block displays the view result of the previous day. Only with a registration attempt the output is updated, no matter whether I logged in, or a registration attempt is started.

In the views I have changed under -> ADVANCED -> cache: „tag based" to "time-based" with duration of 1 hour for query results and output format.

Unfortunately, the result is the same: the output block is not updated according to the new day. Now I have deactivated the data caching of the view module, in the hope that tomorrow the display is now updated independently.

If this does not work, only to log in once the day to force an update?

Admin/performance:

Admin/performance

Modules:

cache Modules

views/settings/advanced:

views/settings/advanced

The View:

View left side

The View (extended)

view extended

  • Could you share what kind of caching mechanisms you have in your server setup ? A screenshot of admin/config/development/performance page would also be helpful. Do you have installed any modules that interact with cache ? Furthermore, instead of waiting for a day to invalidate the cache you could setup a scenario where you filter on datetime instead only on datem while experimenting. – O V Mar 12 '17 at 3:05
  • Hi Oleg, as a new user I can’t publish images (up to 10 posts). Server provider: nothing known, sorry. Drupal: /admin/config/development/performance: Cache: Page cache maximum cache: <no caching> aggregate CSS files and JS files: disabled. Modules: Internal Dynamic Page Cache - enabled Internal Page Cache - enabled Filter on Datetime: The content type has an date field. In the View I’ve filtered this for: equal to : „now“. The preview shows this content correctly. Cache of this View: Time based (1hour/ 1 hour) general view cache: disabled – Frank Giesecke Mar 12 '17 at 12:32
  • Hi Frank, For brevity and clarity of the post, can you just add the appropriate screenshots in the post, since the formatting of the comments is not ideal for readability. – O V Mar 12 '17 at 12:46
  • Tanks, I've done so. – Frank Giesecke Mar 12 '17 at 13:56
4

The issue you have is with the module Internal Page Cache for anonymous users. You have several options:

If you want to serve for anonymous users a newly built page on each request the same way as for logged in users, then uninstall the Internal Page Cache module. The dynamic page cache will still cache pages, but does respect the cache contexts and max-age you set on the page elements.

Performance wise it is not a good idea to do this, so it might be better to configure a max-age for the Internal Page Cache, see this answer https://drupal.stackexchange.com/a/196557/47547, where you use an event subscriber to set an Expires time in the response.

If this is only for Views, another option is to modify the route definition of the view by setting a no_cache option, see this answer https://drupal.stackexchange.com/a/230242/47547

In all cases you need to configure /admin/config/development/performance for external caches like the browser cache.

  • > If this is only for Views... Yes, this is at this time Views only. > another option is to modify the route definition of the view by setting a no_cache option, see this answer ... This exceeds my knowledge and my possibilities at this time – Frank Giesecke Mar 12 '17 at 12:37
  • This is easy with Drupal Console, create a module drupal generate:module, create the route subscriber drupal generate:routesubscriber and to look up the route name of the view drupal router:debug – 4k4 Mar 12 '17 at 16:04
  • ... wait, you say the view is a block, then you need the second option, setting an Expires Response Header, but this should also be pretty much straightforward with Drupal Console. – 4k4 Mar 12 '17 at 16:11
  • I'm testing locally with Acquia dev desktop. There I'cant install Drupal Console... It says: "You must execute the following composer commands: composer require drupal/console:~1.0 --prefer-dist --optimize-autoloader composer update drupal/console --with-dependencies" nothing goes composer: command not found – Frank Giesecke Mar 12 '17 at 16:42
  • You need composer. This is the first result in google docs.acquia.com/resource/composer I've found. If you still have problems, ask another question and tag it with acquia-dev-desktop. – 4k4 Mar 12 '17 at 17:11
0

My solution:

  • View: -> Advanced -> Query settings -> Disable SQL rewriting: Yes.
  • Views Caching: Time-based (2 hours/2 hours

Works as expected.

Tanks to all.

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.