0

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

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

1 Answer 1

0

The way to invalid the Cache in a Block is with

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

This comes from BlockBase

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

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.