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). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). 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). 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 provides advanced caching options for Drupal Views, allowing users to precisely control cache tags and contexts for improved performance. It enables fine-grained cache tag manipulation, including exclusion by pattern, and can modify cache contexts for specific view displays. Misconfiguration can lead to incorrect cache behavior.

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
1 year ago
Releases (12 mo)
0 ▼ from 7
Maintenance
Dormant

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