This module provides additional cache tags to allow for more granular cache invalidation. It enables tagging content based on entity type and bundle, allowing you to invalidate caches for all nodes or specifically for nodes of a certain type, like "article."
Provides some handy extra cache tags, so you can for example tag a block that deals with a certain node type, with the cache tag of that node type.
The module provides the following cache tags for you to use:
handy_cache_tags:[entity_type]
handy_cache_tags:[entity_type]:[entity_bundle]
For example with nodes of the bundle "article" this would make the following cache tags available:
handy_cache_tags:node
handy_cache_tags:node:article
The first would invalidate on any node (which by coincidence also is provided through the "node_list" cache tag in core). The second would invalidate on any node being created, updated or deleted with the bundle article.
To generate these tags for your render array, you can use the following:
$build['#cache'] = [
'tags' => [
// This one generates the bundle specific cache tag.
\Drupal::service('handy_cache_tags.manager')->getBundleTag('node', 'article'),
// This one generates the entity type cache tag.
\Drupal::service('handy_cache_tags.manager')->getTag('node'),
],
];
If your render array deals with an entity, you can also use the following helper functions:
// Get all tags for an entity:
\Drupal::service('handy_cache_tags.manager')
->getEntityTags(EntityInterface $entity);
// Get entity type tag from an entity:
\Drupal::service('handy_cache_tags.manager')
->getEntityTypeTagFromEntity(EntityInterface $entity);
// Get bundle tag from entity:
\Drupal::service('handy_cache_tags.manager')
->getBundleTagFromEntity(EntityInterface $entity);
Ask your assistant about Handy cache tags
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
Activity
Releases
| Version | Type | Core | PHP | Release date | |
|---|---|---|---|---|---|
| 8.x-1.5 | Stable | 8–11 | Oct 27, 2024 |