Problem/Motivation

Currently if a response is not cacheable Drupal sets X-Drupal-Dynamic-Cache = UNCACHEABLE, but in some cases it does not. See DynamicPageCacheSubscriber::onResponse for details.

Steps to reproduce

NA

Proposed resolution

Always set X-Drupal-Dynamic-Cache header.

  1. This changes the existing X-Drupal-Dynamic-Cache: UNCACHEABLE to X-Drupal-Dynamic-Cache: UNCACHEABLE (poor cacheability).
  2. This adds X-Drupal-Dynamic-Cache: UNCACHEABLE (no cacheability) (for responses which aren't instances of CacheableResponseInterface).
  3. This adds X-Drupal-Dynamic-Cache: UNCACHEABLE (policy) (when the Dynamic Page Cache request/response policy tagged services deny caching).

This makes it much easier for developers to understand what the Dynamic Page Cache module is doing, and why.

Remaining tasks

Review

User interface changes

NA

API changes

NA

Data model changes

Don't think so

Release notes snippet

Page Cache & Dynamic Page Cache response headers improved to include more detail about the cacheability. See change record.

CommentFileSizeAuthor
#134 2951814-nr-bot.txt90 bytesneeds-review-queue-bot
#126 2951814-nr-bot.txt90 bytesneeds-review-queue-bot
#120 2951814-nr-bot.txt90 bytesneeds-review-queue-bot
#101 2951814-nr-bot.txt150 bytesneeds-review-queue-bot
#87 interdiff_84-85.txt2.34 KBsanjayk
#87 interdiff_80-84.txt3.39 KBsanjayk
#85 2951814-85.patch45.81 KBsanjayk
#84 2951814-84.patch44.25 KBsanjayk
#81 2951814-80.patch42.73 KBsanjayk
#79 2951814-79.patch45.17 KBfranz
#70 2951814-70.patch62.02 KBwim leers
#70 interdiff.txt2.04 KBwim leers
#67 2951814-67.patch50.47 KBwim leers
#67 interdiff.txt19.09 KBwim leers
#66 2951814-66.patch31.47 KBwim leers
#66 interdiff.txt2.39 KBwim leers
#64 2951814-64.patch30.1 KBwim leers
#61 interdiff-57-61.txt6.02 KBelaman
#61 2951814-61.patch29.16 KBelaman
#57 2951814-57.patch30.05 KBwim leers
#57 interdiff.txt1.1 KBwim leers
#55 2951814-55.patch28.13 KBkala4ek
#51 2951814-51.patch28.96 KBwim leers
#51 interdiff.txt1.93 KBwim leers
#48 2951814-48.patch27.53 KBwim leers
#46 interdiff_41_46.txt7.43 KByobottehg
#46 2951814-46.patch26.74 KByobottehg
#41 2951814-41.patch27.43 KBwim leers
#41 interdiff.txt5.79 KBwim leers
#39 2951814-39.patch22.12 KBwim leers
#37 2951814-37.patch22.12 KBwim leers
#37 interdiff.txt4.88 KBwim leers
#31 2951814-30.patch17.68 KBwim leers
#31 interdiff.txt5.6 KBwim leers
#29 interdiff.txt3.59 KBwim leers
#28 2951814-28.patch16.81 KBwim leers
#27 2951814-26.patch14.33 KBwim leers
#27 interdiff.txt1.05 KBwim leers
#19 2951814-19.patch13.32 KBwim leers
#19 interdiff.txt1.84 KBwim leers
#14 2951814-14.patch11.53 KBwim leers
#14 interdiff-12-14.txt854 byteswim leers
#12 2951814-12.patch11.88 KBwim leers
#12 interdiff-10-12.txt3.73 KBwim leers
#10 2951814-10.patch8.21 KBwim leers
#10 interdiff-6-10.txt918 byteswim leers
#6 2951814-6.patch7.36 KBwim leers
#6 interdiff-5-6.txt5.44 KBwim leers
#5 2951814-5.patch1.98 KBwim leers

Issue fork drupal-2951814

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Chi created an issue. See original summary.

wim leers’s picture

Title: Always set X-Drupal-Dynamic-Cache header » Always set X-Drupal-Dynamic-Cache header, even for responses that don't implement CacheableResponseInterface
Status: Active » Postponed (maintainer needs more info)
Issue tags: +D8 cacheability
  1. Only CacheableResponseInterface response objects can get X-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()).
  2. Any response object that does not implement CacheableResponseInterface cannot 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: INELIGIBLE for case 2 help?

chi’s picture

Status: Postponed (maintainer needs more info) » Active

The 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?

chi’s picture

Only CacheableResponseInterface response objects can get X-Drupal-Dynamic-Cache: UNCACHEABLE

Well, we do not always send X-Drupal-Dynamic-Cache header even for CacheableResponseInterface responses.

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new1.98 KB

Does it make sense?

Yes and no. For Page Cache, we also don't set a X-Drupal-Cache header 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.

wim leers’s picture

StatusFileSize
new5.44 KB
new7.36 KB

This updates the expectations per the changes in #5.

The last submitted patch, 5: 2951814-5.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 6: 2951814-6.patch, failed testing. View results

chi’s picture

UNCACHEABLE (no cacheability)

Well, 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?

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new918 bytes
new8.21 KB

Status: Needs review » Needs work

The last submitted patch, 10: 2951814-10.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new3.73 KB
new11.88 KB

Apparently the layout_builder module has impressively detailed test coverage! 👏

Status: Needs review » Needs work

The last submitted patch, 12: 2951814-12.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new854 bytes
new11.53 KB
  1. +++ b/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php
    @@ -156,6 +156,7 @@ public function onResponse(FilterResponseEvent $event) {
    +      $response->headers->set(self::HEADER, 'UNCACHEABLE (no cacheability)');
    
    @@ -167,7 +168,7 @@ public function onResponse(FilterResponseEvent $event) {
    +      $response->headers->set(self::HEADER, 'UNCACHEABLE (poor cacheability)');
    
    @@ -191,6 +193,7 @@ public function onResponse(FilterResponseEvent $event) {
    +      $response->headers->set(self::HEADER, 'UNCACHEABLE (policy)');
    

    These 3 are explicitly tested by \Drupal\Tests\dynamic_page_cache\Functional\DynamicPageCacheIntegrationTest::testDynamicPageCache().

  2. +++ b/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php
    @@ -184,6 +185,7 @@ public function onResponse(FilterResponseEvent $event) {
    +      $response->headers->set(self::HEADER, 'UNCACHEABLE (subrequest)');
    

    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-Cache header.

    That last remaining failure confirms this suspicion:

    --- Expected
    +++ Actual
    @@ @@
    -MISS
    +UNCACHEABLE (subrequest)
    

    So, reverting that one line.

wim leers’s picture

Issue summary: View changes

IS updated to clarify the changes.

wim leers’s picture

Issue summary: View changes
wim leers’s picture

@Chi: Thoughts? :)

chi’s picture

This works for me.
I've created a small module to debug site cacheability. It plays nice with this patch.

+++ b/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php
@@ -191,6 +192,7 @@ public function onResponse(FilterResponseEvent $event) {
+      $response->headers->set(self::HEADER, 'UNCACHEABLE (policy)');

What if we apply the same to Page cache module?
https://github.com/drupal/drupal/blob/8.5.0/core/modules/page_cache/src/...

wim leers’s picture

StatusFileSize
new1.84 KB
new13.32 KB

What if we apply the same to Page cache module?

I do like the idea of keeping both modules similar/consistent in their headers!

Let's see which tests fail.

chi’s picture

Title: Always set X-Drupal-Dynamic-Cache header, even for responses that don't implement CacheableResponseInterface » Always set X-Drupal-Cache and X-Drupal-Dynamic-Cache headers, even for responses that are not cacheable
Component: dynamic_page_cache.module » cache system

Changing the title and component since the issue scope has been slightly extended.

chi’s picture

Status: Needs review » Reviewed & tested by the community

Looks good for me.

wim leers’s picture

Component: cache system » request processing system

Cool :) Changing component again — sorry for the nitpicking!

Note that we should still add page_cache test coverage.

pifagor’s picture

+

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

We 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.

wim leers’s picture

Issue tags: -Needs change record
chi’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC as the change record has been created.

wim leers’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.05 KB
new14.33 KB

Test coverage for page_cache.

wim leers’s picture

StatusFileSize
new16.81 KB

And I think we can actually add X-Drupal-Cache: UNCACHEABLE (no cacheability) to page_cache too? At which point page_cache's headers would entirely match dynamic_page_cache's, except for UNCACHEABLE (poor cacheability), which does not make sense for page_cache.

wim leers’s picture

StatusFileSize
new3.59 KB

Forgot #28's interdiff apparently.

chi’s picture

@Wim Leers, should we mention this in the CR as well?

wim leers’s picture

StatusFileSize
new5.6 KB
new17.68 KB

Let's untangle request policy vs response policy, and be consistent about it.

wim leers’s picture

#30: Yes, but first let's see whether A) it actually works, B) whether you and Alex Pott think it's a good idea :)

wim leers’s picture

chi’s picture

I like having those headers as detailed as possible.

The last submitted patch, 28: 2951814-28.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 31: 2951814-30.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new4.88 KB
new22.12 KB

This should make many of the existing tests pass! Maybe even all.

Status: Needs review » Needs work

The last submitted patch, 37: 2951814-37.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new22.12 KB

#37 was rolled against 8.5. Oops. Rebased on top of 8.6.

Status: Needs review » Needs work

The last submitted patch, 39: 2951814-39.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new5.79 KB
new27.43 KB

The remaining test failures are all old WebTestBase tests that needed updating now that page_cache communicates the reason for not caching explicitly.

wim leers’s picture

Ready for final review! :)

dawehner’s picture

+++ b/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php
@@ -156,6 +156,7 @@ public function onResponse(FilterResponseEvent $event) {
     if (!$response instanceof CacheableResponseInterface) {
+      $response->headers->set(self::HEADER, 'UNCACHEABLE (no cacheability)');
       return;

@@ -167,7 +168,7 @@ public function onResponse(FilterResponseEvent $event) {
-      $response->headers->set(self::HEADER, 'UNCACHEABLE');
+      $response->headers->set(self::HEADER, 'UNCACHEABLE (poor cacheability)');

I'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

chi’s picture

I searched D8 contrib codebase on this.

search_api/tests/src/Functional/CacheabilityTest.php
52:    $this->assertSession()->responseHeaderEquals('x-drupal-dynamic-cache', 'UNCACHEABLE');

cache_alter/src/EventSubscriber/DynamicCacheAlter.php
86:      $response->headers->set(self::HEADER, 'UNCACHEABLE');

field_encrypt/src/Tests/FieldEncryptCacheTest.php
51:    $this->assertEqual('UNCACHEABLE', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Page with encrypted fields is uncacheable.');

monitoring/src/Tests/MonitoringServicesTest.php
129:    $this->assertEqual('UNCACHEABLE', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER),

jsonapi/tests/src/Functional/NodeTest.php
340:    $this->assertResourceResponse(200, FALSE, $response, $this->getExpectedCacheTags(), $expected_cache_contexts, FALSE, 'UNCACHEABLE');

jsonapi/tests/src/Functional/ResourceTestBase.php
969:      //  $expected_cacheability->getCacheMaxAge() === 0 ? 'UNCACHEABLE' : 'MISS'
2070:      //   $expected_cacheability->getCacheMaxAge() === 0 ? 'UNCACHEABLE' : 'MISS'

jsonapi/tests/src/Functional/ResourceResponseTestTrait.php
158:      $cacheability->setCacheMaxAge(($dynamic_cache[0] === 'UNCACHEABLE') ? 0 : Cache::PERMANENT);

business_core/profiles/business/tests/src/Functional/StandardTest.php
184:    $this->assertEqual('UNCACHEABLE', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER), 'Site-wide contact page cannot be cached by Dynamic Page Cache.');

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.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

yobottehg’s picture

StatusFileSize
new26.74 KB
new7.43 KB

Rebased because it did not apply on 8.6.2

Status: Needs review » Needs work

The last submitted patch, 46: 2951814-46.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new27.53 KB

@yobottehg Thanks! Seems something went wrong though. Rebased it too.

wim leers’s picture

#43: Great point! I think an additional *-Explain or *-Reason header 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?

Status: Needs review » Needs work

The last submitted patch, 48: 2951814-48.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new1.93 KB
new28.96 KB

Status: Needs review » Needs work

The last submitted patch, 51: 2951814-51.patch, failed testing. View results

ndobromirov’s picture

Patch does not apply to latest 8.7 dev, nor 8.6.3 stable. Needs a re-roll.

ndobromirov’s picture

Issue tags: +Needs reroll
kala4ek’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new28.13 KB

Here is the reroll for current 8.7 dev

Status: Needs review » Needs work

The last submitted patch, 55: 2951814-55.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new1.1 KB
new30.05 KB

@ndobromirov++

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC - Looks great! Love it :)

The last submitted patch, 41: 2951814-41.patch, failed testing. View results

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Needs a reroll

elaman’s picture

Status: Needs work » Needs review
StatusFileSize
new29.16 KB
new6.02 KB

I've tried to reroll the patch.

Status: Needs review » Needs work

The last submitted patch, 61: 2951814-61.patch, failed testing. View results

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new30.1 KB

Rebased #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.

Status: Needs review » Needs work

The last submitted patch, 64: 2951814-64.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new2.39 KB
new31.47 KB

There is one case where Dynamic Page Cache doesn't yet set a header:

    // Don't cache the response if Dynamic Page Cache's request subscriber did
    // not fire, because that means it is impossible to have a Dynamic Page
    // Cache hit. This can happen when the master request is for example a 403
    // or 404, in which case a subrequest is performed by the router. In that
    // case, it is the subrequest's response that is cached by Dynamic Page
    // Cache, because the routing happens in a request subscriber earlier than
    // Dynamic Page Cache's and immediately sets a response, i.e. the one
    // returned by the subrequest, and thus causes Dynamic Page Cache's request
    // subscriber to not fire for the master request.
    // @see \Drupal\Core\Routing\AccessAwareRouter::checkAccess()
    // @see \Drupal\Core\EventSubscriber\DefaultExceptionHtmlSubscriber::on403()
    $request = $event->getRequest();
    if (!isset($this->requestPolicyResults[$request])) {
      return;
    }

That case was being hit.

This should allow more tests to pass. I haven't touched the JSON:API tests yet.

wim leers’s picture

StatusFileSize
new19.09 KB
new50.47 KB

This 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).

The last submitted patch, 66: 2951814-66.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 67: 2951814-67.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new2.04 KB
new62.02 KB

The presence of X-Drupal-Cache and X-Drupal-Dynamic-Cache on even uncacheable responses is A) pointless, B) extremely disruptive. So let's not do that anymore.

Status: Needs review » Needs work

The last submitted patch, 70: 2951814-70.patch, failed testing. View results

joshua.boltz’s picture

I 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.

wim leers’s picture

I actually found this patch really useful lately in debugging some caching issues with a REST resource.

🥳 That's what this is aiming to achieve!

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.

Exactly! The problem is not you not being smart enough, the problem is Drupal's response caching modules not communicating explicitly enough.

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.

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:

There were 3 failures:

1) Drupal\Tests\datetime\Functional\EntityResource\EntityTest\EntityTestDateonlyTest::testPost
Failed asserting that false is true.

/var/www/html/core/tests/Drupal/KernelTests/AssertLegacyTrait.php:35
/var/www/html/core/modules/rest/tests/src/Functional/ResourceTestBase.php:415
/var/www/html/core/modules/rest/tests/src/Functional/ResourceTestBase.php:465
/var/www/html/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php:854

2) Drupal\Tests\datetime\Functional\EntityResource\EntityTest\EntityTestDateonlyTest::testPatch
Failed asserting that false is true.

/var/www/html/core/tests/Drupal/KernelTests/AssertLegacyTrait.php:35
/var/www/html/core/modules/rest/tests/src/Functional/ResourceTestBase.php:415
/var/www/html/core/modules/rest/tests/src/Functional/ResourceTestBase.php:465
/var/www/html/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php:1080

3) Drupal\Tests\datetime\Functional\EntityResource\EntityTest\EntityTestDateonlyTest::testDelete
Failed asserting that false is true.

/var/www/html/core/tests/Drupal/KernelTests/AssertLegacyTrait.php:35
/var/www/html/core/modules/rest/tests/src/Functional/ResourceTestBase.php:415
/var/www/html/core/modules/rest/tests/src/Functional/ResourceTestBase.php:465
/var/www/html/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php:1322

All three are due to the first line here not succeeding:

    else {
      $this->assertTrue($response->hasHeader('X-Drupal-Cache'));
      $this->stringStartsWith('UNCACHEABLE (', $response->getHeader('X-Drupal-Cache')[0]);
    }

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 a X-Drupal-Cache response header.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

chi’s picture

We may also put cache information to server timing header.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

wim leers’s picture

franz’s picture

StatusFileSize
new45.17 KB

Since 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.

sanjayk’s picture

#79 apply successfully on 8.9 so, just run test case for 8.9

sanjayk’s picture

StatusFileSize
new42.73 KB

re-roll patch for 9.2

franz’s picture

I 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.

berdir’s picture

This 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.

sanjayk’s picture

StatusFileSize
new44.25 KB

Fixed few test cases.

sanjayk’s picture

StatusFileSize
new45.81 KB

Fixed more test cases.

wim leers’s picture

@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 😅🤓

sanjayk’s picture

StatusFileSize
new3.39 KB
new2.34 KB

Thanks @Wim Leers for reminding me. I was totally forgot to upload.
Sure, I will keep in mind and upload interdiff in future :)

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

neclimdul made their first commit to this issue’s fork.

neclimdul’s picture

Status: Needs work » Needs review

Took a stab at moving this forward.

  1. Needed a reroll, conflicted with #3228634: Move tests for integrations between QuickEdit and other modules into QuickEdit so that it can more easily be moved into contrib. That seems to be because #2266809: Make QuickEditEntityFieldAccessCheck::access() use the $account that's passed in was accidentally merged with this so I reverted those changes.
  2. A bunch of tests seem to be failing because EntityResourceTestBase::testDelete was asserting cache headers but they where removed on uncacheable methods in an earlier patch.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

joachim made their first commit to this issue’s fork.

joachim’s picture

Rebased 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?

heddn’s picture

Title: Always set X-Drupal-Cache and X-Drupal-Dynamic-Cache headers, even for responses that are not cacheable » Improve X-Drupal-Cache and X-Drupal-Dynamic-Cache headers, even for responses that are not cacheable

Updated title. And the latest MR needs to have its base update to 9.5 or 10.1.

andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
neclimdul’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll

rerolled. Open to alternative names but don't have any suggestions. Good enough for developer experience header?

wim leers’s picture

I'd love to RTBC this but it's not passing tests anymore 🙈

Could we find different single words for the different flavours of UNCACHEABLE?

I don't see how. The all-caps word is the result: HIT, MISS or UNCACHEABLE. 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? 😊

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new150 bytes

The 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.

claudiu.cristea made their first commit to this issue’s fork.

claudiu.cristea’s picture

Status: Needs work » Needs review
claudiu.cristea’s picture

Updated the change record to match the MR.

claudiu.cristea’s picture

Narrowed from 268 to 8 failures.

smustgrave’s picture

Status: Needs review » Needs work

Moving to NW for the failures.

wim leers’s picture

This would be fantastic to ship at last! 🤞

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wim leers’s picture

Priority: Normal » Major
Issue tags: +Needs reroll

Needs a new MR against 11.x. Let's finally land this — we now have fantastic new tooling such as StandardPerformanceTest (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! 😊

vakulrai made their first commit to this issue’s fork.

vakulrai’s picture

Status: Needs work » Needs review

I 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 !

smustgrave’s picture

Status: Needs review » Needs work

Believe the failures are showing that the solution needs to be relooked at.

vakulrai’s picture

Status: Needs work » Needs review

All test Passed , moving to review !

smustgrave’s picture

Issue tags: -Needs reroll

Hiding patches and old MRs for clarity.

smustgrave changed the visibility of the branch 2951814-cache-header-10.1.x to hidden.

smustgrave changed the visibility of the branch 2951814-always-set-x-drupal-cache to hidden.

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Updated CR version

Updated issue summary to include release notes, as I think this is a good highlight.

Believe the reroll is correct.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new90 bytes

The 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.

mxr576 made their first commit to this issue’s fork.

mxr576’s picture

Status: Needs work » Needs review

Back to review \o/

mxr576’s picture

mxr576’s picture

Even if this gets merged, this other issue still remains relevant.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Ran 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

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new90 bytes

The 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.

mxr576’s picture

Status: Needs work » Needs review
mxr576’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC after rebase.

mxr576’s picture

Status: Reviewed & tested by the community » Needs work

Meh... ofc simple rebase wasn't enough

Drupal\Tests\jsonapi\Functional\UserTest::testGetIndividual
Failed asserting that false is identical to true.

core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php:1030

This should be also caused by the recently merged https://git.drupalcode.org/project/drupal/-/commit/9fc1bc9ac5a785ebf6e88......

mxr576’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rebase seems good.

mxr576’s picture

(rebased)

anybody’s picture

This 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!

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new90 bytes

The 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.

mxr576’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: +no-needs-review-bot

Gitlab says MR still applies, back to RTBC.

neclimdul’s picture

Status: Reviewed & tested by the community » Needs work

Checking GL, it does say "Merge conflicts must be resolved." so think this needs another rebase.

mxr576 changed the visibility of the branch drupal-2951814 to hidden.

mxr576 changed the visibility of the branch 2951814-always-set-x-drupal-cache to active.

mxr576’s picture

Indeed... :sadpanda: Rebasing again... PHPStorm could auto-resolve all :fingers-crossed:.

 git rebase origin/11.x
Auto-merging core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php
Auto-merging core/modules/jsonapi/tests/src/Functional/NodeTest.php
CONFLICT (content): Merge conflict in core/modules/jsonapi/tests/src/Functional/NodeTest.php
Auto-merging core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
CONFLICT (content): Merge conflict in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Auto-merging core/modules/layout_builder/tests/src/Functional/LayoutSectionTest.php
Auto-merging core/modules/node/tests/src/Functional/NodeBlockFunctionalTest.php
Auto-merging core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
error: could not apply d8f6085835... Applying https://www.drupal.org/files/issues/2021-02-24/2951814-85.patch
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply d8f6085835... Applying https://www.drupal.org/files/issues/2021-02-24/2951814-85.patch

mxr576 changed the visibility of the branch 2951814-always-set-x-drupal-cache to hidden.

mxr576 changed the visibility of the branch drupal-2951814 to active.

mxr576’s picture

Status: Needs work » Needs review
Issue tags: -no-needs-review-bot
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

believe rebase is good.

ankitv18 made their first commit to this issue’s fork.

ankitv18’s picture

Rebased the forked branch ~~ RTBC++

mxr576’s picture

Rebased, there was only one conflict in a test file that PHPStorm could autoresolve easily.

❯ git rebase origin/11.x
Auto-merging core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Auto-merging core/modules/language/tests/src/Functional/LanguageBrowserDetectionAcceptLanguageTest.php
Auto-merging core/modules/page_cache/tests/src/Functional/PageCacheTest.php
CONFLICT (content): Merge conflict in core/modules/page_cache/tests/src/Functional/PageCacheTest.php
Auto-merging core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Auto-merging core/modules/rest/tests/src/Functional/ResourceTestBase.php
Auto-merging core/modules/system/tests/src/Functional/Session/SessionTest.php
Auto-merging core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php
Auto-merging core/modules/user/tests/src/Functional/UserPasswordResetTest.php
mxr576’s picture

Issue tags: +10.4.0 release notes

May I recommend this feature to 10.4.0 release notes?

grasmash’s picture

This 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.

alexpott’s picture

Updated issue credit. Removed credit for partial rerolls and tried to credit everyone who contributed test fixing & comments that help direct the work.

alexpott’s picture

Version: 11.x-dev » 10.4.x-dev
Status: Reviewed & tested by the community » Needs work

Committed 19f80f6 and pushed to 11.x. Thanks!

Let's backport this to 10.4.x

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

Created 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

  • alexpott committed 19f80f65 on 11.x
    Issue #2951814 by wim leers, mxr576, vakulrai, claudiu.cristea,...

  • alexpott committed f9f2e0b6 on 10.4.x
    Issue #2951814 by wim leers, mxr576, vakulrai, claudiu.cristea,...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.