Views cache settings not added to headers

Created on 9 March 2021, over 3 years ago
Updated 20 November 2024, 14 days ago

Problem/Motivation

Cache settings provided by the views config are not rendered in the headers of the JSON output, which means that the display's cache does not get invalidated when it should.

Steps to reproduce

  1. Create a JSON:API view.
  2. Set the View caching to tag-based.
  3. View the headers of the rendered view -- the views cache tags will not be listed.

This affects both the basic Views cache tags, and custom tags provided by Views Custom Cache Tags β†’ .

Time-based cache settings are also not bubbling up.

Proposed resolution

Explicitly adding the view's cache tags using $bubbleable_metadata->addCacheTags($view->getCacheTags()); fixes the problem for tag-based caching. I'm not sure how to access the time-based caching settings or send them to the headers.

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jesss

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡―πŸ‡΄Jordan yahyaalhamad Palestine

    This is an old issue, but I had problems with caching when different users are logged in, and other times, a 403 error is cached, this cache attempts to fix the issue by adding the dependency using the view render array, I made sure to also add the cache contexts to fix the issue of different users when attempting to use the API. Also, make sure to add cache dependency when the view access is denied.

Production build 0.71.5 2024