Cacheable HTML and JSON responses handled differently when HTTP 4xx occurs

Created on 31 May 2024, 3 months ago
Updated 17 July 2024, about 2 months ago

Problem/Motivation

This is a dedicated, spin-off issue for discussing potential solutions for the problem that was identified in 🐛 Access cacheability is not correct when "view own unpublished content" is in use Needs work , see related conversation: https://git.drupalcode.org/project/drupal/-/merge_requests/8198#note_321385

TL;DR

Okay, so originally the code looked like this: https://github.com/drupal/core/blob/b73ad25123ab5e1c07562f2c577842e52662...

X-Drupal-Dynamic-Cache header WAS NOT expected in the response.
The only thing that have changed are relates to Node entities, because from now they are sometime bubbling up user cache context that triggers DynamicPageCacheSubscriber's if (!$this->shouldCacheResponse($response)) {} logic that runs sooner than if (!isset($this->requestPolicyResults[$request])) {}.
So even if Dynamic Page Cache SHOULD ignore a response because it was made by a sub request, for Node entities, it does it ignore it by adding the X-Drupal-Dynamic-Cache header

This issue was not discovered before because:
1. There was no cacheable JSON response test in dynamic_page_cache
2. There was no cacheable JSON response test in dynamic_page_cache that would fail with an HTTP 4xx error.

Having this fixed is a soft-blocker of closing 🐛 Access cacheability is not correct when "view own unpublished content" is in use Needs work and 🐛 Insufficient cacheability information bubbled up by UserAccessControlHandler Active because there are a not-too-dirty-workaround in test for mitigating this difference.

Steps to reproduce

See failing test in MR.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Dynamic page cache 

Last updated 9 days ago

Created by

🇭🇺Hungary mxr576 Hungary

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