I've created a custom module to show On This Days in a block but they are not changing each day until I flush the caches.

I call the entity:

public function build() {
    $query = \Drupal::entityQuery('node');
    $query->condition('status', 1);
    $query->condition('type', 'on_this_day');
    $query->condition('field_filter_date', '-' . date("m-d"), 'CONTAINS');
    $entity_ids = $query->execute();


and then return from the build function like this:

return array(
        '#markup' => $content,
        '#cache' => array(
            'max-age' => 0,

Any ideas? I'm thinking entity cache or something but I'm quite new to this and not too sure

  • 5
    Does this answer your question? How to use max-age – Hudri Nov 24 '20 at 17:06
  • Hi, I am using that but I suspect that it's the entities caching or something? – MysticQuack Dec 1 '20 at 12:46

The way to invalid the Cache in a Block is with

   * {@inheritdoc}
  public function getCacheMaxAge() {
    return 0;

This comes from BlockBase

  • Thanks, I do have this in the code but no luck I'm afraid. – MysticQuack Dec 1 '20 at 12:46

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.