Closed (fixed)
Project:
Drupal core
Version:
10.4.x-dev
Component:
request processing system
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
10 Mar 2018 at 15:03 UTC
Updated:
16 Oct 2024 at 22:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
wim leersCacheableResponseInterfaceresponse objects can getX-Drupal-Dynamic-Cache: UNCACHEABLE(i.e. the response varies by a high-cardinality cache context or a high-invalidation frequency cache tag, or a max-age=0 — see\Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber::shouldCacheResponse()).CacheableResponseInterfacecannot ever be processed by Dynamic Page Cache, and thus doesn't get any response header at all.I do understand that this can be confusing though. Would setting
X-Drupal-Dynamic-Cache: INELIGIBLEfor case 2 help?Comment #3
chi commentedThe onResponse handler has five return statements. Two of them are are preceded by
$response->headers->set();. The issue is about setting headers for the other three for easy debugging.Does it make sense?
Comment #4
chi commentedWell, we do not always send X-Drupal-Dynamic-Cache header even for CacheableResponseInterface responses.
Comment #5
wim leersYes and no. For Page Cache, we also don't set a
X-Drupal-Cacheheader on every response. Why should Dynamic Page Cache do so then? But you're right that Dynamic Page Cache is harder to understand.Let's do this!
This patch should cause failures in the existing test coverage.
Comment #6
wim leersThis updates the expectations per the changes in #5.
Comment #9
chi commentedWell, I was going to propose the same approach (clarifying why the response is uncachable). My concern was that we might expose to much internal information. Is it worth to use http.response.debug_cacheability_headers flag here?
Comment #10
wim leersComment #12
wim leersApparently the
layout_buildermodule has impressively detailed test coverage! 👏Comment #14
wim leersThese 3 are explicitly tested by
\Drupal\Tests\dynamic_page_cache\Functional\DynamicPageCacheIntegrationTest::testDynamicPageCache().This one is not yet, and is also the one I was least certain about. Based on the comment, this should probably not set a
X-Drupal-Dynamic-Cacheheader.That last remaining failure confirms this suspicion:
So, reverting that one line.
Comment #15
wim leersIS updated to clarify the changes.
Comment #16
wim leersComment #17
wim leers@Chi: Thoughts? :)
Comment #18
chi commentedThis works for me.
I've created a small module to debug site cacheability. It plays nice with this patch.
What if we apply the same to Page cache module?
https://github.com/drupal/drupal/blob/8.5.0/core/modules/page_cache/src/...
Comment #19
wim leersI do like the idea of keeping both modules similar/consistent in their headers!
Let's see which tests fail.
Comment #20
chi commentedChanging the title and component since the issue scope has been slightly extended.
Comment #21
chi commentedLooks good for me.
Comment #22
wim leersCool :) Changing component again — sorry for the nitpicking!
Note that we should still add
page_cachetest coverage.Comment #23
pifagor+
Comment #24
alexpottWe should have a change record so people are informed about this. The CR should also document what the new header values mean. Especially
UNCACHEABLE (poor cacheability)is that is a bit cryptic.Comment #25
wim leersAgreed! CR created: https://www.drupal.org/node/2958442.
Comment #26
chi commentedBack to RTBC as the change record has been created.
Comment #27
wim leersTest coverage for
page_cache.Comment #28
wim leersAnd I think we can actually add
X-Drupal-Cache: UNCACHEABLE (no cacheability)topage_cachetoo? At which pointpage_cache's headers would entirely matchdynamic_page_cache's, except forUNCACHEABLE (poor cacheability), which does not make sense forpage_cache.Comment #29
wim leersForgot #28's interdiff apparently.
Comment #30
chi commented@Wim Leers, should we mention this in the CR as well?
Comment #31
wim leersLet's untangle request policy vs response policy, and be consistent about it.
Comment #32
wim leers#30: Yes, but first let's see whether A) it actually works, B) whether you and Alex Pott think it's a good idea :)
Comment #33
wim leersComment #34
chi commentedI like having those headers as detailed as possible.
Comment #37
wim leersThis should make many of the existing tests pass! Maybe even all.
Comment #39
wim leers#37 was rolled against 8.5. Oops. Rebased on top of 8.6.
Comment #41
wim leersThe remaining test failures are all old
WebTestBasetests that needed updating now thatpage_cachecommunicates the reason for not caching explicitly.Comment #42
wim leersReady for final review! :)
Comment #43
dawehnerI'm curious what are potential risks that code out there relies on this exact output? Could we reduce the risk by maybe doing something like having an additional -explanation header or so? I don't see any discussion about this yet. I could imagine that for example tests in contrib modules stop working
Comment #44
chi commentedI searched D8 contrib codebase on this.
Seems like the header is only used in tests to check the response changeability. Anyway I don't think HTTP headers should be considered as a part of public API.
I propose we create followup issues for these contributed projects to update their tests.
Comment #46
yobottehg commentedRebased because it did not apply on 8.6.2
Comment #48
wim leers@yobottehg Thanks! Seems something went wrong though. Rebased it too.
Comment #49
wim leers#43: Great point! I think an additional
*-Explainor*-Reasonheader is worth considering. OTOH, the updates to test coverage this may require in some projects are A) trivial, B) valuable. They're valuable because they result in explicitly documenting why some responses are uncacheable!Hence #44's proposal sounds reasonable to me. I'm happy to help create patches for affected contrib modules.
What do you think, @dawehner?
Comment #51
wim leersComment #53
ndobromirov commentedPatch does not apply to latest 8.7 dev, nor 8.6.3 stable. Needs a re-roll.
Comment #54
ndobromirov commentedComment #55
kala4ekHere is the reroll for current 8.7 dev
Comment #57
wim leers@ndobromirov++
Comment #58
fabianx commentedRTBC - Looks great! Love it :)
Comment #60
alexpottNeeds a reroll
Comment #61
elamanI've tried to reroll the patch.
Comment #64
wim leersRebased #57.
Note that with JSON:API having landed, most JSON:API integration tests will also fail with this change; they'll need to be updated.
Comment #66
wim leersThere is one case where Dynamic Page Cache doesn't yet set a header:
That case was being hit.
This should allow more tests to pass. I haven't touched the JSON:API tests yet.
Comment #67
wim leersThis updates many JSON:API assertions but may not result in a much higher number of passing tests, due to the way that DrupalCI counts tests (if even one of 10 test methods in a test class fails, that's counted as a single failing test).
Comment #70
wim leersThe presence of
X-Drupal-CacheandX-Drupal-Dynamic-Cacheon even uncacheable responses is A) pointless, B) extremely disruptive. So let's not do that anymore.Comment #72
joshua.boltz commentedI actually found this patch really useful lately in debugging some caching issues with a REST resource.
I didn't actually understand at first that a missing X-Drupal-Cache header means it's not cacheable with internal page cache. It was nice to actually still see the header stating it's actually uncacheable.
I did find it strange that Insomnia shows `X-Drupal-Cache UNCACHEABLE (request policy)` whereas Postman shows `X-Drupal-Cache →UNCACHEABLE (response policy)` for the same URL.
Comment #73
wim leers🥳 That's what this is aiming to achieve!
Exactly! The problem is not you not being smart enough, the problem is Drupal's response caching modules not communicating explicitly enough.
Are you sure that one of them wasn't
X-Drupal-Dynamic-Cache?Would you like to take a stab at finishing this issue by solving the last test failures? The number of failing tests is high, but many of them have the same root cause. For example:
All three are due to the first line here not succeeding:
Why not? Because the 404 response is not triggered by Drupal, but very early by Symfony, in
\Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest(). So we'll either need to refine our expectations or ensure that 404 responses for non-existent routes also have aX-Drupal-Cacheresponse header.Comment #75
chi commentedWe may also put cache information to server timing header.
Comment #78
wim leers#3089957: Set X-Drupal-Cache-Max-Age to aid in debugging #cache fun landed. Let's land this too now!
Comment #79
franzSince all of the failing hunks from #70 patches were tests, I just applied partially to make the patch work on 8.9. Need to go back and review those tests.
Comment #80
sanjayk commented#79 apply successfully on 8.9 so, just run test case for 8.9
Comment #81
sanjayk commentedre-roll patch for 9.2
Comment #82
franzI just want to add that after my attempt, I found that it did not solve my issue. As anonymous user, I always get a HIT on a REST response that should have max-age cacheability. Logged-in users correctly invalidate the cache. I will try to debug this but I don't have much time for this personal project so I might just give up and go with a tag + cron.
Comment #83
berdirThis is not meant to solve anything, it just adds debug output (it is a task not a bugfix). What you're looking for is #2352009: Bubbling of elements' max-age to the page's headers and the page cache and https://www.drupal.org/project/cache_control_override or a similar custom solution. But beware, there be dragons, there are reason why this isn't happening atm, which are documented in that issue and just enabling that module could cause all kinds of pages to not be cached anymore.
Comment #84
sanjayk commentedFixed few test cases.
Comment #85
sanjayk commentedFixed more test cases.
Comment #86
wim leers@sanjayk Thanks for pushing this forward! 🙏👏
Could you please add interdiffs for the patches you posted, and for all future patches? Otherwise it's rather difficult to see what you changed 😅🤓
Comment #87
sanjayk commentedThanks @Wim Leers for reminding me. I was totally forgot to upload.
Sure, I will keep in mind and upload interdiff in future :)
Comment #91
neclimdulTook a stab at moving this forward.
EntityResourceTestBase::testDeletewas asserting cache headers but they where removed on uncacheable methods in an earlier patch.Comment #95
joachim commentedRebased the MR on 9.5.x.
However, I'm not sure about the choice of strings such as 'UNCACHEABLE (poor cacheability)'. So far, they are single words all in caps - clear and legible.
Could we find different single words for the different flavours of UNCACHEABLE?
Comment #96
heddnUpdated title. And the latest MR needs to have its base update to 9.5 or 10.1.
Comment #97
andypostComment #98
neclimdulrerolled. Open to alternative names but don't have any suggestions. Good enough for developer experience header?
Comment #99
wim leersI'd love to RTBC this but it's not passing tests anymore 🙈
I don't see how. The all-caps word is the result:
HIT,MISSorUNCACHEABLE. The parenthetical provides the reason. You may be interested in just the result and not care about the reason. The reason is especially helpful as a developer who aims to make a response cacheable. So … I think this is already as simple and clear as it can be? 😊Comment #101
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #104
claudiu.cristeaComment #105
claudiu.cristeaUpdated the change record to match the MR.
Comment #106
claudiu.cristeaNarrowed from 268 to 8 failures.
Comment #107
smustgrave commentedMoving to NW for the failures.
Comment #108
wim leersThis would be fantastic to ship at last! 🤞
Comment #110
wim leersNeeds a new MR against
11.x. Let's finally land this — we now have fantastic new tooling such asStandardPerformanceTest(thanks to #3352851: Allow assertions on the number of database queries run during tests and many follow-ups) that this would be a valuable addition to, especially for real-world sites. Just today, I helped out a colleague in Acquia's Professional Services department, and it'd have been far simpler to narrow down root causes if this would've existed. #3421164: Log every individual query in performance tests landed earlier today too, so I'm convinced we can do this one as well! 😊Comment #113
vakulrai commentedI have rerolled to 11.x and have brought down the test failure to 6 :), please review the reroll and suggest path forward to fix the remaining test failures.
Thanks !
Comment #114
smustgrave commentedBelieve the failures are showing that the solution needs to be relooked at.
Comment #115
vakulrai commentedAll test Passed , moving to review !
Comment #116
smustgrave commentedHiding patches and old MRs for clarity.
Comment #119
smustgrave commentedUpdated CR version
Updated issue summary to include release notes, as I think this is a good highlight.
Believe the reroll is correct.
Comment #120
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #122
mxr576Back to review \o/
Comment #123
mxr576Comment #124
mxr576Even if this gets merged, this other issue still remains relevant.
Comment #125
smustgrave commentedRan test-only feature https://git.drupalcode.org/issue/drupal-2951814/-/jobs/1740771 which shows test coverage
CR is well written with the examples
+1 from me
Comment #126
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #127
mxr576Comment #128
mxr576Back to RTBC after rebase.
Comment #129
mxr576Meh... ofc simple rebase wasn't enough
This should be also caused by the recently merged https://git.drupalcode.org/project/drupal/-/commit/9fc1bc9ac5a785ebf6e88......
Comment #130
mxr576Comment #131
smustgrave commentedRebase seems good.
Comment #132
mxr576(rebased)
Comment #133
anybodyThis will further improve and simplify cache debugging! Thank you all very much for your hard work on this. Very much looking forward to this functionality!
Comment #134
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #135
mxr576Gitlab says MR still applies, back to RTBC.
Comment #136
neclimdulChecking GL, it does say "Merge conflicts must be resolved." so think this needs another rebase.
Comment #139
mxr576Indeed... :sadpanda: Rebasing again... PHPStorm could auto-resolve all :fingers-crossed:.
Comment #142
mxr576Comment #143
smustgrave commentedbelieve rebase is good.
Comment #145
ankitv18 commentedRebased the forked branch ~~ RTBC++
Comment #146
mxr576Rebased, there was only one conflict in a test file that PHPStorm could autoresolve easily.
Comment #147
mxr576May I recommend this feature to 10.4.0 release notes?
Comment #148
grasmash commentedThis would certainly have saved me hours of debugging. Perhaps this is a bridge too far, but it would also help to identify which modules are adding which tags/contexts.
Comment #149
alexpottUpdated issue credit. Removed credit for partial rerolls and tried to credit everyone who contributed test fixing & comments that help direct the work.
Comment #150
alexpottCommitted 19f80f6 and pushed to 11.x. Thanks!
Let's backport this to 10.4.x
Comment #152
alexpottCreated the backport MR - I wanted a full test run. There were no merge conflicts so I'm going to set to RTBC in the hope it is green. If it is, I will cherry-pick the 11.x commit to 10.4.x
Comment #155
alexpott