I am developing a small application, I have to list the nodes of type article in an endpoint that I have in a module:
When I add an article, I am forced to clear the drupal cache, but the client does not want to have to do this, since the creation of the articles will be automated, I know that there are ways to handle the contexts, tags, cache keys, but I have never managed to understand exactly how this works and I think this would be a good example to understand it.
You should have a look on Cache API to understand how the cache system works in Drupal.
In above case, you will want to use Cache tags because they describes dependencies on data. In particular, you need to add node_list
- list cache tag for Node
entities (invalidated whenever any Node
entity is updated, deleted or created):
return [
'#theme' => 'test_cache',
'#items' => $items,
'#cache' => [
'tags' => ['node_list'],
],
];
You can see the common cache tags here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.