I want to display the date in a block and make sure that it is always up-to-date (i.e. not storing an old cached value).

Currently the date does not change, unless the cache is cleared ( via admin/config/development/performance or drush cr )

It would appear that Drupal 8 does have a setting in the web admin UI for block caching, according to the question in: Has the Block Cache Settings from Drupal 8 been back-ported to Drupal 7?

Screenshot of the Drupal 8 block cache settings from that question: Drupal 8 Block Cache settings

However, the author of that question did not provide the specific URL path to this web UI admin settings (And I have asked them in the comments, linking to this question)

Can you advise where the block cache settings are in Drupal 8 and if it can turn off the cache for a block, please?

In my searching so far I have come across programmatic examples for switching off the cache.

I'm a developer and in the past for Drupal 8 I have done this programmatically for a custom block implemented in code in a custom module so I can but this approach would seem to be unnecessary extra work for turning off the cache for a particular block built in the UI (rather than in code). I would not like to have to add this for each particular block created in the UI.

Programmatic examples are:

Further information what am doing

I have implemented a custom block using today's date as a token via the blocks UI: admin/structure/block/block-content/types and created a block type from this using admin/structure/block/block-content and then placing it in the block structure using admin/structure/block

I am storing this as part of the config (yaml/yml) made possible using simple_block module which adds capability to store block config in the configuration system (so that I can import and export config as yaml drush cex / drush cim. I am hoping that this turning off cache setting for a block cab be stored as config as well.

Thanks for reading and thanks your input.

  • 1
    It was removed a few years back: drupal.org/project/drupal/issues/2458763, block caching is configured via code only now as far as I know
    – Clive
    Commented Jan 9, 2019 at 12:51
  • OK thanks @Clive I was thinking about the standard setting up a Linux cron job in the crontab on my web server, to call Drupal cron. I will use this to clear the cache at midnight. I can set the cache programmatically as well. It's shame, though, this is gone as I can't see how my case would not be useful. I suppose I could write a contrib module to add on cache setting functionality and to make this exportable via config, in conjunction with simple_block module Commented Jan 9, 2019 at 13:02
  • 1
    If I understand the linked issue properly, it's because what you choose on that form wouldn't necessarily represent what's actually going on under the hood (essentially it would be lying). Because cacheability bubbles up from the elements inside the block, any manually set value would be likely to get overridden by one of those, which would probably confuse admins. Might be more to it than that but that was my understanding. I can see how it would be useful in some scenarios, but maybe those are slightly outweighed by the potentially confusing scenarios
    – Clive
    Commented Jan 9, 2019 at 13:06
  • +1 x 2 for your comments Clive - thanks. I agree with your thoughts. I'm happy to go down the programmatic route and/or cron route in any case. Commented Jan 9, 2019 at 13:47


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.