Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
If you create a Views and apply style plugin 'Table' the Cache Max Age is set to 0, which renders the Page uncacheable by dynamic_page_cache.
Context to reproduce the issue:
-User is logged-in (simple user, not admin)
-Page Cache and Dynamic Page Cache modules are enabled
Result on the page with this views:
X-Drupal-Dynamic-Cache: "UNCACHEABLE"
Proposed resolution
Fix the Table style so it becomes cacheable.
This was added in #2464427: Replace CacheablePluginInterface with CacheableDependencyInterface
The diff there was this:
- public function isCacheable() {
- return TRUE;
+ public function getCacheMaxAge() {
+ return 0;
So that is clearly incorrect.
Remaining tasks
Write fixWrite testWrite upgrade pathWrite upgrade path test
Comment | File | Size | Author |
---|---|---|---|
#32 | 2932083-32.patch | 10.42 KB | Lendude |
#32 | interdiff-2932083-29-32.txt | 2.22 KB | Lendude |
#29 | 2932083-29.patch | 10.01 KB | Lendude |
#27 | 2932083-24-8.5.x.patch | 10 KB | Lendude |
#24 | 2932083-24-8.5.x.patch | 10 KB | Lendude |
Comments
Comment #2
andreyjan CreditAttribution: andreyjan at FFW commentedAttaching a patch to fix the issue.
Comment #3
andreyjan CreditAttribution: andreyjan at FFW commentedComment #4
andreyjan CreditAttribution: andreyjan at FFW commentedComment #5
siva_drupal CreditAttribution: siva_drupal as a volunteer and at DrupalPartners for Innoppl Technologies Pvt. Ltd commentedComment #6
siva_drupal CreditAttribution: siva_drupal as a volunteer and at DrupalPartners for Innoppl Technologies Pvt. Ltd commentedHi Andreyjan,
I successfully applied the patch. But still, the HTTP response header returns the "UNCACHEABLE" state for "X-Drupal-Dynamic-Cache". I hope the patch #2 is failed.
Comment #7
andreyjan CreditAttribution: andreyjan at FFW commentedsiva_drupal
Try to check as simple user. Admin users get UNCACHEABLE dynamic cache because of an issue in Toolbar module. Check these issues:
https://www.drupal.org/project/drupal/issues/2899392
https://www.drupal.org/project/drupal/issues/2854131
My patch fixes only issue coming from views table plugin cache.
Comment #8
andreyjan CreditAttribution: andreyjan at FFW commentedComment #9
siva_drupal CreditAttribution: siva_drupal as a volunteer and at DrupalPartners for Innoppl Technologies Pvt. Ltd commentedComment #10
Lendude@siva_drupal sorry if this duplicates any work you might be doing, but I dove into this and didn't see you'd assigned it to yourself.
The fix looks good, it just needed tests, here is a test only patch and the combined test/fix. The test-only version is also the interdiff to #2
Comment #11
andreyjan CreditAttribution: andreyjan at FFW commentedThanks Lendude!
Comment #13
siva_drupal CreditAttribution: siva_drupal as a volunteer and at DrupalPartners for Innoppl Technologies Pvt. Ltd commented@lendude and @andreyjan patch #10 is not working for me. Still, the "X-Drupal-Dynamic-Cache" returns the same "UNCACHEABLE" state.(uncachable_user.png)
Comment #14
siva_drupal CreditAttribution: siva_drupal as a volunteer and at DrupalPartners for Innoppl Technologies Pvt. Ltd commentedComment #15
andreyjan CreditAttribution: andreyjan at FFW commentedHi siva_drupal,
As I mentioned this patch fixes only one one issue which breaks Dynamic page cache. There might be other too.
Comment #16
Lendude@siva_drupal try re-saving the View after applying the patch. For some reason that's needed for me to get this to work. Clearing the cache doesn't help.
I'm a little confused why this is needed though. But it does indicate we need something like an upgrade path for this.Ok this setting gets saved to config on save and doesn't get checked at run time.
So yeah, we need an upgrade path for this.
Comment #17
siva_drupal CreditAttribution: siva_drupal as a volunteer and at DrupalPartners for Innoppl Technologies Pvt. Ltd commentedHi @Lendude and @andreyjan after re-saving the views the patch #10 working fine. Thanks for the update.
Comment #18
larowlanThis was added in #2464427: Replace CacheablePluginInterface with CacheableDependencyInterface
The diff there was this:
So that is clearly incorrect, hence this change is appropriate.
Comment #19
larowlanmissing visibility
public
, fails PHPCSComment #20
Lendude@larowlan thanks for taking a look. Updated the IS to include your research.
We also needed an upgrade path. This addresses #19 and adds the upgrade path and a test for it.
Comment #22
LendudeBleh, ignore #20.
Now without the Webdriver changes included.....
Comment #24
LendudeSorry about the noise..... now a 8.4.x and an 8.5.x patch.
Comment #25
LendudeComment #26
LendudeComment #27
LendudeThe 8.4.x patch has the wrong post update, no idea how that happend.
Upping the 8.5.x patch by itself to make it clear what needs reviewing.
Comment #29
Lendudeneeded another reroll, *fingers crossed*
Comment #30
dawehnerFor better longterm readability I would have built a list of views to e saved. continue 2 might be something people don't know it exists. Still, this is my personal choice, I just wanted to put it out :)
I had a quick look whether the table style plugin provides the necessary cache contexts I would expect: url query parameters for table sorting, so enabling is totally fine.
Comment #31
alexpottLet's batch. Just to be safe. All updates that are loops we should batch because we cannot know how many things there are.
Comment #32
Lendude@alexpott yeah absolutely, stole your code from #2942986: Views should be dependent on providers of table data via hook_views_data :)
Also fixed a copy/paste leftover.
Comment #33
dawehnerThank you for implementing the batch saving!
Comment #34
alexpottCommitted and pushed 4c127e1a9b to 8.6.x and f5f0896031 to 8.5.x. Thanks!
Backported to 8.5.x as an important bugfix for cacheability of sites.
Comment #38
cilefen CreditAttribution: cilefen as a volunteer commentedPossibly related: #2999869: InvalidArgumentException: Placeholders must have a trailing [] if they are to be expanded with an array of values. in Drupal\Core\Database\Connection->expandArguments() when updating the database to 8.6.x.
Comment #39
Morbus IffSee also #3038408: Update config/*/views.view.*.yml tables with correct dynamic cache max-age.