Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Usage Milestone: Google Analytics Module google_analytics crossed 1,000 active installs. Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Release: GraphQL Compose Codegen 1.1.2 Minor update available for module graphql_compose_codegen (1.1.2). Release: Mapy.com 1.1.3 Minor update available for module mapycom (1.1.3). Release: Ckeditor5 entity browser 3.0.3 Minor update available for module ckeditor5_entity_browser (3.0.3). Release: Ckeditor5 entity browser 3.0.1 Minor update available for module ckeditor5_entity_browser (3.0.1). Release: Ckeditor5 entity browser 3.0.2 Minor update available for module ckeditor5_entity_browser (3.0.2). Release: Teamleader Integration 4.0.2 Minor update available for module teamleader (4.0.2). Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Views Custom Cache Tags

7,764 sites Security covered Drupal 8–11 Views ecosystem
View on drupal.org

This module allows for more granular control over cache invalidation for Drupal views. Instead of using a generic cache tag for all views listing entities, it enables developers to define custom cache tags based on view filters, arguments, or even custom code. This helps ensure that only relevant views are cleared from the cache when content changes, improving performance.

Overview

Views in Drupal 8 automatically adds cache tags to every view so that their content can be invalidated when it changes (and can be cached as long as possible until they do).

However, Drupal 8 only has a single list cache tag for every entity type. Every view that lists nodes is tagged with node_list and will be invalidated when a node is added, changed or deleted.

Views usually have filters. They might list nodes of a specific type, or nodes that are tagged with a certain term and a combination of three other filters. By using more specific cache tags, it is possible to only update views that actually might list the changed node.

This module replaces the hardcoded cache tag with a form that allows developers to set different cache tags based on configuration of the view. It is also possible to set cache tags based on arguments/contextual filters.

Since #2145751: Introduce ENTITY_TYPE_list:BUNDLE cache tag and add it to single bundle listing (8.9+), it is possible to use the default bundle cache tags (<entity_type>_list:<bundle>, e.g. node_list:article) in views until drupal core supports these automatically in the cache plugin. Alternatively or additionally, custom code can be used similar or more specific cache tags, e.g. based on the promoted or a taxonomy field.

function yourmodule_node_presave(NodeInterface $node) {
  $tags = ['mysite:node:' . $node->getType()];
  if ($node->hasField('field_category')) {
    $tags[] = 'mysite:node:category:' . $node->field_category->target_id;
  }
  // If the category changes, also invalidate the original value.
  if ($node->original && $node->node->original->hasField('field_category')) {
    $tags[] = 'mysite:node:category:' . $node->field_category->target_id;
  }

  Cache::invalidateTags(array_unique($tags));
}

Status

The module is in an early phase and will likely be extended in the future, for example with functionality to invalidate cache tags based on configuration.

Features

  • A views cache plugin that allows to configured the added cache tags
  • Support for setting cache tags based on passed in arguments
  • Optional support for time-based invalidation on top of a custom cache tag, to account for things like relative date filters (such as upcoming events)

Documentation

Further documentation will follow.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

1 tracked project depends on this one

Activity

Tracked releases
2
Tracked since
Feb 2025
Latest release
5 months ago
Releases (12 mo)
1
Maintenance
Active

Releases

Version Type Core Release date
8.x-1.5 Stable 8–11 Mar 3, 2026
8.x-1.4 Stable 8–11 Feb 8, 2025