Prevent creating unnecessary cache entries

Created on 22 March 2024, 7 months ago

Problem/Motivation

When not using JavaScript to forward the query arguments, the url.query_args cache context is added to pages. This means that different query argument values create new cache entries, even for query arguments that are not forwarded (and so don't create different cached content).

This bug is tedious on sites using query arguments for search in combination with facets. Each different search query invoked by visitors causes cache entries to be created for the rendered entities/results (and being identical to each other). This will flood the cache bins and hurt performance (as the rendered entities shown on the page are only served from the cache when the search query matches and not when they are shown for a different search and facet combination).

Steps to reproduce

Assuming a typical Drupal setup, where (render) caching is enabled, the "Carry URL address query params across pages" module is installed. Navigate to a page, e.g., an article node, and verify that a cache entry is stored in the render cache bin. Add a query argument to the URL, e.g., ?foo, and verify that a new cache entry is stored in the render cache bin, while foo is not carried across rendered URLs.

Proposed resolution

Add the allowed/configured query argument keys to the cache context ID, i.e., url.query_args:foo where 'foo' is a configured key that has to be carried over. This way, only the query arguments that influence page content (the URLs having the query arguments attached) change the cache context.

Remaining tasks

  • Review proposed changes

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇳🇱Netherlands watergate

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024