Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

views_advanced_cache

123 sites Security covered
View on drupal.org

The views advanced cache module provides a cache plugin that allows more precise manipulation of cache tags and cache contexts.

It is intended for advanced technical users with an understanding of the Drupal 8 Cache API.

Misconfiguration can lead to incorrect or stale cache results including bypassing of standard content access restrictions.

Features

  • A views cache plugin that allows adding and removing a view display's cache metadata such as contexts, tags and setting max-age.
  • Additionally the cache metadata of each row can be modified.
  • Cache tags can be excluded by exact match or regular expression.
  • Dynamic cache tags based on argument token replacements.

Configuration

This module exposes a cache plugin named Advanced Caching on each view display locate under Advanced ->Other ->Caching settings.

Settings to modify caching metadata applied to a view display are divided into Cache Tags, Cache Contexts, and Max-Age and Results Cache. The cache tag modifications can also be processed for each row.

Note that this module does not trigger the invalidation of the custom tags. See below for example use cases, including one to add and invalidate a custom tag.

Override the node_list cache tag

By default views adds a node_list cache tag to all node views and invalidates cache entries with this tag whenever ANY node is created or updated. By overriding the default node_list cache tag with a bundle-specific alternative we can improve the cache HIT rate of views when unrelated content is saved.

The code below will invalidate the custom cache tag on node CRUD events.

<?php
/**
 * Invalidate a "my_custom:node_list:{bundle}" cache tag on node save.
 */
function my_custom_module_node_presave(NodeInterface $node) {
  $tags = ['my_custom:node_list:' . $node-&gt;getType()];
  Cache::invalidateTags($tags);
}

And the below cache tag settings will cache a view until page nodes are saved.

Cache tags to add:

my_custom:node_list:page

Cache tags to exclude:

node_list

Excluding using regular expressions

A list of nodes will include a cache tag of node:[nid] for every node included in the list. Invalidating any one of these cache tags, such as when saving an included node, will invalidate all views it is included in. Normally this would be a desired behavior, but if the goal is to cache a list of nodes for as long as possible regardless of their content being updated, then these specific tags can be removed using regular expression.

Cache tags to add:

my_custom:node_list:page

Cache tags to exclude:

node_list

Cache tags to exclude via regular expression:

/node\:[0-9]+/

In this configuration saving any of the nodes would not trigger invalidation of the view. The view would stay in cache until max-age, or manual cache flush.

By using the hook from the Override the node_list cache tag example, the list can still be invalidated using my_custom:node_list:page.

Add / Remove cache contexts

Modifying cache contexts is a riskier proposition as incorrect configuration may result in incorrect results and not just stale cached results. USE WITH CAUTION A solid knowledge of the cache api cache contexts and views cache configs is recommended.

This option allows altering of a view display plugin's cache_metadata contexts. An example use is to limit the url.query_args in a rest_export view as below:

Cache tags to add:

url.query_args:page
url.query_args:items_per_page
url.query_args:offset
url.query_args:my_custom_filter

Cache tags to exclude:

- url.query_args

This can be used to override the default pager caching per all page query arguments instead only considering those relevant to the view.

Related Modules

Activity

Total releases
7
First release
May 2025
Latest release
10 months ago
Release cadence
8 days
Stability
86% stable

Release Timeline

Releases

Version Type Release date
2.0.2 Stable Jun 18, 2025
8.x-1.2 Stable Jun 18, 2025
2.0.1 Stable May 16, 2025
8.x-1.1 Stable May 16, 2025
2.0.0 Stable May 1, 2025
8.x-1.0 Stable May 1, 2025
2.x-dev Dev May 1, 2025