Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Varbase FAQs 9.2.1 Minor update available for module varbase_faqs (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

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.

Activity

Total releases
2
First release
Feb 2025
Latest release
4 months ago
Releases (12 mo)
1
Maintenance
Active

Releases

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