Problem/Motivation
Debugging caching can be hard.
https://www.previousnext.com.au/blog/ensuring-drupal-8-block-cache-tags-...
...
Although http.response.debug_cacheability_headers: true
lets you see your tags and contexts, there's no easy way to see WTF is going on with max-age.
Unfortunately, just knowing what your #cache['max-age']
is doesn't tell you much until this pit of snakes is untangled:
- #2352009: [pp-3] Bubbling of elements' max-age to the page's headers and the page cache
- #2449749: Add #cache['downstream-ttl'] to force expiration after a certain time and fix #cache['max-age'] logic by adding #cache['age']
- #2835068: PageCache caching uncacheable responses (violating HTTP/1.0 spec) + D8 intentionally disabling HTTP/1.0 proxies = WTF
- #2951814: Improve X-Drupal-Cache and X-Drupal-Dynamic-Cache headers, even for responses that are not cacheable
- ...
But, at least knowing you're trying to do the right thing could help in the meanwhile. ;)
It also seems very useful to be able to compare Expires
vs. Cache-Control
vs. X-Drupal-Cache-Max-Age
in various circumstances and configurations as we try to navigate the snake pit.
Proposed resolution
If http.response.debug_cacheability_headers: true
is in your services.yml file, also set a X-Drupal-Cache-Max-Age
response header.
Remaining tasks
Write codeWrite testsReviews + refinementsRTBCCommit- Reach back down into the snake pit and try to make progress on making
max-age
actually work. :/
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
Probably none.
Comment | File | Size | Author |
---|---|---|---|
#18 | 3089957-18.patch | 5.67 KB | dww |
#7 | 3089957-6.patch | 5.43 KB | dww |
Comments
Comment #2
dwwComment #3
Wim LeersThis is a subset of #2951814: Improve X-Drupal-Cache and X-Drupal-Dynamic-Cache headers, even for responses that are not cacheable, let's push that issue forward instead :)
Comment #4
dwwRe: #3: I see this as a stand-alone, orthogonal feature request to aid in debugging. Nothing more. ;) Looking at the latest patch in there, I don't see anything like what I'm proposing here.
But, I added that to the growing list of issues in the snake pit. ;)
Meanwhile, here's test coverage.
RTBC?
Comment #7
dwwre: https://www.drupal.org/pift-ci-job/1447632 -- wow:
I guess the attached is the right way to fix this?
Comment #8
dwwRe: #3: I added this to the summary:
I think resolving those issues (and writing test for them) will be easier if we have this, so we can compare expectations with reality.
Meanwhile, to warn others of the fun, I made these edits to the main Cache max-age doc:
https://www.drupal.org/node/2541404/revisions/view/11105792/11617646
(added a "Limitations of max-age" header at the bottom of the page).
Cheers,
-Derek
Comment #9
mr.baileysCaching in Drupal is governed by the combination of cache tags, cache contexts and max-age. When providing information meant for debugging purposes, it makes sense to output all three pieces of information, instead of just the first two. This change seems to fall outside of the current scope of #2951814: Improve X-Drupal-Cache and X-Drupal-Dynamic-Cache headers, even for responses that are not cacheable, so +1 to keep these issues separate.
The patch and tests look good to me. One thing I would consider is replacing the 'special' values with descriptive text (-1 = "Permanent", 0 = "Uncacheable")
If this gets commited, and since this is a DX improvement, we should issue a CR explaining the new header, and update existing documentation.
Comment #10
xjmComment #12
Krzysztof DomańskiI added change record X-Drupal-Cache-Max-Age header.
Comment #13
dwwWonderful, thanks @Krzysztof Domański!
I did a few edits to the CR, but mostly it looked great.
Cheers,
-Derek
Comment #15
Krzysztof DomańskiUnrelated random test failure. Back to RTBC.
Comment #16
alexpottFrom #9 hasn't been addressed. I'm ambivalent - on one hand it makes it easier to read on the other it obscures the real value set in code. @dww that do you think?
Comment #17
Krzysztof DomańskiI am voting for a real value... Since it's debug value, can we combine both values?
Comment #18
dwwI'm ambivalent as well. Seems like anyone using this feature is going to be doing low-level debugging and can handle interpreting the values themselves. I still prefer #7.
But here's a working version of #17 if y'all prefer. #17 is using == for both comparison and assignment. ;) So I borrowed a = from each assignment and gave it to each comparison. ;) Also shorted the variable name.
Not sure about translating these special values, since this seems like some mighty low-level code, and I'm not sure we can assume we have a working translation system at this point. Seems like some potential bloat and complication for only limited value.
Comment #19
Krzysztof DomańskiIMO we don't need to translate these special values, because only developers can see these values. Additionally, it adds extra work, that we can avoid.
Comment #20
alexpottCommitted 488870e and pushed to 9.1.x. Thanks!
Comment #21
alexpottI committed the patch in #18 - the additional detail is useful.
Comment #23
dwwSweet, thanks!
I see the CR is now published with the right version info, thank to whomever took care of that.
Cheers,
-Derek
Comment #25
Wim LeersLet's continue this work in #2951814: Improve X-Drupal-Cache and X-Drupal-Dynamic-Cache headers, even for responses that are not cacheable!