Problem/Motivation
We added this in [#2222293]. But it really makes very little sense, because each block should automatically get the max age it can be cached for. Back then, that seemed an impossibility. But a few weeks ago, #2429257: Bubble cache contexts landed, which made it a reality.
(Bubbling also is sufficient for custom blocks — thanks to fields' and filters' ability to associate cache tags, contexts and max-age.)
If we're asking the user to indicate how long a block can be cached, we've already failed: the user shouldn't even have to make that choice. It should happen automatically, based on the contents of the block.
Another reason we should remove the max-age support: because it's not something that's part of blocks themselves; it's part of BlockBase
! Hence the config schema and config are actually written against BlockBase
instead of BlockPluginInterface
, which is very, very wrong.
It does make sense to be able to configure a max-age in very advanced use cases, where you want invalidation not to happen via tags, but you want a block to be cached for at least X seconds. But that's up to the block plugin itself.
Proposed resolution
Remove the UI.
Remaining tasks
TBD
User interface changes
No more max-age configuration when configuring BlockBase
-based blocks.
API changes
- The config schema is changed.
BlockBase::getCacheMaxAge()
returnsCache::PERMANENT
instead of the configured max-age (which defaulted to zero), thus strongly encouraging all blocks extending fromBlockBase
to be cacheable.
Beta phase evaluation
Issue priority | Major because 1) despite being horrible for usability in the first place, 2) it also makes caching less efficient than it can be, and 3) it ends up being a lie to the user: we present the configured cache max-ages as the only cache max-ages being varied by, but the contents of the block may (and almost always do) bubble additional max-ages (the lowest max-age wins), thus making the UI not only unusable, but also a lie that we cannot possibly explain clearly. |
---|---|
Prioritized changes | The main goal of this issue is usability + performance + DX |
Disruption | Disruptive for custom/contributed modules in a minor way: if they provide blocks, and they extend the BlockBase class to do so, they won't have to alter the block's configuration form anymore to enforce a certain max-age. |
Comment | File | Size | Author |
---|---|---|---|
#56 | block-remove-max-cache-ui-2458763-56.patch | 17.02 KB | Wim Leers |
Comments
Comment #1
Wim LeersBlocked on #2428805: Remove the ability to configure a block's cache contexts.
Comment #2
Wim LeersBlocked on #2428805: Remove the ability to configure a block's cache contexts.
Comment #3
BerdirThis is not correct and rather irrelevant for this issue :) There's almost nothing that is not by-display in views, you can't change the table/entity type you're querying (not the base table, at least), but other than that, there are no limits, including cache configuration.
=> Remove that from the issue summary or rewrite it (but I would remove it, because doesn't matter for this issue).
Comment #4
Wim LeersDone.
Comment #5
Wim Leers#2428805: Remove the ability to configure a block's cache contexts landed, now unblocked.
Comment #6
Bojhan CreditAttribution: Bojhan commentedRemoving UI's++
Comment #7
Wim Leers@Berdir: thinking about this some more, isn't what you actually need for your use cases not the ability to force a certain max-age, but rather the ability to set a min-age?
Comment #8
BerdirYes, I was thinking about that too, that would be an interesting way to solve that problem.
Not quite sure how to support that, though. We could change Renderer to always allow invalidated items too, and then check if they set a min-age and keep using that if it hasn't expired yet?
We had that for the page cache removed it, I don't remember anymore why exactly.
Comment #9
Fabianx CreditAttribution: Fabianx for Drupal Association commentedThe relevant comment by Berdir was:
#2428805-16: Remove the ability to configure a block's cache contexts
I think the examples of something that changes time based on the contents of the view make sense, where invalidation is too costly (cache tag invalidation - while precise costs a lot of write DB performance).
I also wondered about alteration possibilities of bubbled data.
Would #post_render work? I assume not.
In the worst case a contrib/ render_cache 8.x could provide a Renderer that either
a) accepts additional #render_cache_pre_bubbling and #render_cache_post_bubbling callbacks - not to be mixed up with #post_render_cache and #pre_render ...
b) an optional alter hook that is called per cache item, because I do not care about the overhead on my own sites
However I think we should do something in core to allow more customizability on the API level, too.
That is - as I just realized - another issue though.
Comment #10
amateescu CreditAttribution: amateescu for Drupal Association commentedAdding a tag that will help the beta-to-beta effort later :)
Comment #11
Fabianx CreditAttribution: Fabianx for Drupal Association commentedThe question is:
Do we really need a UI feature for that except for views?
And I think we don't ...
Comment #12
m1r1k CreditAttribution: m1r1k commentedI will try during devdays:)
Comment #13
m1r1k CreditAttribution: m1r1k commentedComment #14
Fabianx CreditAttribution: Fabianx for Drupal Association commentedTagging
Comment #16
Wim LeersThe block config entity's config schema, as well as the UI test have not yet been updated.
Comment #17
m1r1k CreditAttribution: m1r1k commentedComment #19
m1r1k CreditAttribution: m1r1k commentedmeh, wrong place for form item.
@wim-leers Why do we need update schema? We only remove UI for choosing cache life-time (but keep it for views)?
Comment #21
m1r1k CreditAttribution: m1r1k commentedFix BlockInterfaceTest
Comment #22
Wim LeersThis also needs to be removed.
Two accidental changes in this file, can be removed :)
Interesting :) You're keeping this around just for Views.
Fabianx said in #11:
Let's hear what Berdir thinks.
If we want to keep this, then we still want to change the block config entity's config schema. Because as of this patch, it's no longer something that applies to all blocks, but only to the Views blocks. So it's up to Views to provide a custom schema for views blocks.
If you need help with that, please ping me in IRC tomorrow, and I'll find somebody who can help you :) That's definitely not the simplest task. See the cheat sheet at http://hojtsy.hu/blog/2014-dec-12/drupal-8-configuration-schema-cheat-sheet
Comment #23
m1r1k CreditAttribution: m1r1k commentedComment #24
Wim LeersJust one super stupid typo, then this is RTBC :)
s/tg/tag/
Comment #25
m1r1k CreditAttribution: m1r1k commentedComment #26
Fabianx CreditAttribution: Fabianx for Drupal Association commentedAssigning to Berdir for review.
@Berdir: Are we sure we really need a UI in the blocks to set the max-age? Especially if views time based caching would / should set max-age automatically, too ...
And a hook_block_view_BLOCK_ID_alter is simple to do from the outside and the inside ...
Comment #27
BerdirOk, ok ;)
I just didn't want it to be removed together with the other issue, so that we can evaluate this properly and separately.
As discussed with Wim, I think the views block should expose max age properly, so that for example a block with a random sort isn't cached. We need #2464427: Replace CacheablePluginInterface with CacheableDependencyInterface for that. Not actually for that example (0 or permanent would work for that), but for time based caching.
(Trick question: if you have a randomly sorted view that is explicitly cached for 1h, what should the max-age of that block be?)
Comment #28
Fabianx CreditAttribution: Fabianx for Acquia commentedI don't think it is the view block that needs to expose that but the time based views cache plugin.
As that is broken in views right now, are we sure we cannot go ahead here and fix views afterwards?
Comment #29
Fabianx CreditAttribution: Fabianx for Acquia commentedPostponing on #2464427: Replace CacheablePluginInterface with CacheableDependencyInterface after discussion.
While it is views that is broken right now of not setting max-age properly, this can be workaround-ed partially by configuring a block max-age.
Therefore views supporting max-age is a dependency for this to go in ...
Comment #30
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedComment #31
BerdirPossible way to move forward with this without waiting on #2464427: Replace CacheablePluginInterface with CacheableDependencyInterface, which is somehow behaving weirdly.
Move the cache settings UI to a helper method that's not called by default, keep it on views blocks. Then we can at least remove it from all the other blocks in core..
Comment #32
Wim LeersSounds good. But AFAICT the other issue is pretty much ready, so :)
Comment #33
Bojhan CreditAttribution: Bojhan commentedLets dooooo it! :)
Comment #34
moshe weitzman CreditAttribution: moshe weitzman at Acquia commentedComment #35
Wim Leers… and then it went to uncover like half of all the critical upgrade path criticals…
But now it should really be ready to go in.
This is a straight reroll of #25, just with a bunch of conflicts resolved.
Comment #38
Wim LeersIn this reroll:
LocalActionsBlock
andLocalTasksBlock
updated alsoComment #39
Wim LeersForgot the interdiff.
Comment #42
Wim Leers#2005546: Use branding block in place of page template branding variables (site name, slogan, site logo) just landed and broke this.
Comment #45
Wim LeersComment #48
Wim LeersHAH!
Comment #49
dawehnerAre we really sure we want to change behaviour on existing sites? I mean this basically what happens.
A much less disruptive change would be provide a BC and remove the UI support for it.
Comment #50
Wim LeersI'd wager that 99% have not used this manual override functionality.
Also, see point 3 in the beta evaluation:
This UI and configurability stems from the days that block plugins did not provide this metadata themselves. If something is uncacheable in a block, then that uncacheable thing will bubble it itself (e.g. a form).
Shipping with this capability — even if it's not in the UI — is IMO a super misleading thing; it will almost always end up confusing the user.
Comment #51
Fabianx CreditAttribution: Fabianx for Acquia commentedI agree with #50. Especially - that this functionality should only be used by advanced users and for those it is just an alter hook away.
Compared to D7, where e.g. the block_cache_alter module (which I maintain) provided this additional functionality and in which it was necessary to use time based expiration, the cache tags based expiration is in 90% of the cases the better choice.
Hence I agree with removing that UI and functionality as it is severely misleading.
Comment #52
moshe weitzman CreditAttribution: moshe weitzman at Acquia commentedThis is a nice UI and code cleanup. Only deletions.
Comment #53
BerdirSee #27. Nothing has really changed since then. The other issue has not yet been committed and IMHO, we really should have an integration test that ensures that max-age of a views block is bubbled up correctly. AFAIK, that still doesn't work or does it now?
Comment #54
Wim LeersThe other issue is not yet in, but it has been held up time and time again on other issues. So I wanted to make sure that this issue was at least ready.
Once the other issue lands, Views blocks indeed will bubble max-age from Views.
Comment #55
alexpottNeeds reroll.
Comment #56
Wim LeersRebased. #2511516: Make local tasks and actions hooks provide cacheability metadata, to make the blocks showing them cacheable conflicted with this, and reduces the amount of work this patch has to do. :)
Comment #57
Wim LeersRe-RTBC'ing given that this patch interdiff clearly shows that the only difference with #48 is the removal of a few hunks of changes. The rest is identical.
Comment #59
Wim LeersTestbot again. Sigh.
Comment #62
XanoSeems like random test failures.
Comment #63
catchAgreed with this, the feature is very confusing/misleading as-is, let alone unnecessary.
Committed/pushed to 8.0.x, thanks!
Comment #66
Gábor HojtsyThanks, removing from UX sprint now.
Comment #67
Gábor Hojtsy