Updated: Comment #0
Problem/Motivation
If we want to improve the page cache by removing the "content" cache tag (see #2124957: Replace 'content' cache tag with 'rendered' and use it sparingly), then we must ensure that cache tags exist for all user-modifiable pieces of content on the page.
Placing a new block does not cause the affected page cache entries to be invalidated. In #2158003: Remove Block Cache API in favor of blocks returning #cache with cache tags, this is being fixed by invalidating the "content" cache tag, since that's the only feasible solution for now. But as explained above, we want to get rid of that tag!
Steps to reproduce
- Install Drupal 8 in the Standard profile.
- Enable page caching (go to
admin/config/development/performance, check the "Use internal page cache" setting and set the "Page cache maximum age" setting to e.g. 3 minutes). - Visit the content as the anonymous user (e.g. the front page)
- Place another block (e.g. a second instance of the "Powered by Drupal" block).
- Visit the content as the anonymous user (e.g. the front page)
-
- Expected: the placed block shows up.
- Actual: the placed block doesn't show up, because the stale page cache entry is being served.
Proposed resolution
Set a theme:<theme name> cache tag on each page cache entry.
Remaining tasks
Update drupal_page_set_cache() (or maybe system_page_build()) to set the cache tag, and Block::postSave() in the case of a new block.
The latter is blocked on #2158003: Remove Block Cache API in favor of blocks returning #cache with cache tags.
User interface changes
None.
API changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | interdiff.txt | 2.68 KB | wim leers |
| #17 | theme_cache_tag-2185617-17.patch | 18.86 KB | wim leers |
Comments
Comment #1
wim leersComment #2
wim leersMarking critical since the parent issue is critical and this blocks the parent.
Comment #3
wim leers#2188565: Test coverage for Comment, Custom Block, Node, Taxonomy Term and User entity cache tags is in, which adds base test classes that make it easier to test this :)
Comment #4
voidberg commentedAttaching patch. Did not change the test file which means the current tests will fail.
Comment #5
voidberg commentedComment #7
voidberg commentedReroll patch.
Comment #8
voidberg commentedComment #10
voidberg commentedAdded the theme tag to the tests as well.
Comment #12
drifter commentedRerolling and updating the tests to make them pass. I must admit I'm not very familiar with what goes on behind the scenes, my test fixes will need reviewing.
Comment #13
wim leersGreat work, voidberg & drifter! :)
The place the cache tags were being added was less than ideal, so I moved it to the ideal place:
#type = page's#pre_rendercallback. Also, we must not just yet delete thecontent:1cache tag, because too many things still depend on it.What was still missing, is a cache tag that corresponds to the global theme settings — I noticed this while working on making
SystemBrandingBlockcacheable, which will come with the next reroll.Comment #15
wim leersHere's a reroll with a cacheable
SystemBrandingBlock! Tests fixed also.(Also fixed the link to the appearance settings. And fixed a typo in
LanguageCacheContext.)Comment #17
wim leersComment #18
jibranWe have tests and patch is green. I am unable to find anything questionable in the patch so changing status to RTBC. Thank you @Wim Leers.
Comment #19
alexpottCommitted 407f1d1 and pushed to 8.x. Thanks!
Fixed during commit.
Comment #21
wim leers#19: darn, sorry about that :(