1

I created a page by a module and the cache of that page must be deleted if a node of node-type 'foo' is updated.

How do I do that?

I read https://www.drupal.org/docs/drupal-apis/cache-api/cache-tags

And tried:

mymodule.routing.yml

mymodule.foopage:
  path: '/myurl'
  defaults:
    _controller: '\Drupal\mymodule\MyClass::page'
    _title: 'Foo'
  options:
    _cache_tags:
      - 'node:foo'
  requirements:
    _permission: 'access content'

I tried also _cache_tags node_list:foo

But cache is not rebuild when I update a foo content.

drupal_flush_all_caches works fine, but it seems a bit to heavy.

1 Answer 1

3

The cache tag node_list:foo is correct. But I've never seen that you can add it to a route like this. Normally the route controller returns the cache metadata in $build:

public function page() {
  // build $build
  $build['#cache']['tags'][] = 'node_list:foo';
  return $build;
}
0

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.