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
RenderCache cannot be used as is atm, because its not aware of the default renderer cache contexts.
Proposed resolution
Set the default cache contexts before set() and get(). Remove from Renderer::doRender() (but leave for the is_root_call case).
- Inject the %renderer.config% container parameter
- Use $this->rendererConfig['required_cache_contexts'] in set() to expand the list of used cache contexts
- Use $this->rendererConfig['required_cache_contexts'] in get() to expand the list of used cache contexts
- Remove the required cache context for the #cache keys if-case in Renderer::doRender()
Remaining tasks
- Fix it
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#31 | 2483887-31.patch | 1.07 KB | Wim Leers |
Comments
Comment #1
Fabianx CreditAttribution: Fabianx for Acquia commentedComment #2
Fabianx CreditAttribution: Fabianx for Acquia commentedComment #3
dawehnerThis sounds like a novice task? It reads as if all you need is to ensure those cache contexts.
Comment #4
Fabianx CreditAttribution: Fabianx for Acquia commentedYes, it can be done by a novice.
Comment #5
dawehnerComment #6
Fabianx CreditAttribution: Fabianx for Acquia commentedComment #7
Wim LeersComment #8
joshi.rohit100Comment #9
joshi.rohit100Copy Paste mistake ):
Comment #11
Fabianx CreditAttribution: Fabianx for Acquia commentedNice work, could we have a test for that, please?
Comment #12
dawehnerWhen I used the render cache directly I had to deal also on the
get()
level so yeah tests would be nice.Comment #14
Fabianx CreditAttribution: Fabianx for Acquia commented#12: Yes, you are right, I missed we add it to $pre_bubbling_elements, updated the IS for that.
Comment #15
Wim LeersReroll + one line change to make unit tests pass.
Comment #16
Wim LeersClarify issue.
Comment #17
Wim LeersThis is wrong; it should merge the required cache contexts with those in
$data
. Otherwise the render cache item, when retrieved from cache and used in something else, will not bubble up the required cache context.Of course… one could reason that required cache contexts should not ever be exposed, and should indeed be added this way: at the very last moment, without them showing up while debugging anywhere else in the render pipeline.
But, the reasoning that we've applied in the past is: "less magic, easier debugging". That's why
Renderer::doRender()
does do what I described above.Second: this will introduce some overhead/performance penalty, because it will mean required cache contexts are added both in the
Render
and in theRenderCache
services.That is also the reason why
RenderCache
does not yet deal with required cache contexts in HEAD, which is exactly what this issue is trying to change.The only reason this issue wants to change that is for the very few, very rare occasions where code is using the
RenderCache
service directly. In fact, #2450897: Cache Field views row output was the only occurrence of this. (BTW while trying to find more usages, I also found #2507459: CachePluginBase and subclasses no longer need Renderer/RenderCache services injected.)But, actually… that also doesn't use the
RenderCache
service directly! See #2450897-118: Cache Field views row output and related patches: Which means nothing actually directly talks to theRenderCache
service.Which brings me to my proposal (which is the conclusion I've come to while writing this comment): let's make the
RenderCache
service private. That just enforces what we already know: just use theRenderer
service. That's what turned out to make most sense. This issue is a "bug" or a "problem" only if you want to use this service directly. But that doesn't make a lot of sense. It's tightly coupled to theRenderer
. It helps makeRenderer
more understandable. Let's keep it that way. And thus let's make this service private instead.(Fun detail: this would be nicely symmetrical with
FormBuilder
andFormCache
:FormCache
is private toFormBuilder
too!)Comment #18
Wim LeersComment #19
dawehnerIts unusable anyway, but well, there are a lot of tests in views relying on it, if I remember correctly.
Comment #20
Fabianx CreditAttribution: Fabianx for Acquia commentedI am not yet convinced that we should not push those things to RenderCache though I agree the coupling is tight right now.
There is still the buggy behavior however that is justifying the move.
Comment #21
Wim LeersThere's no actual bug as far
RenderCache
is concerned. It just does what is told, works with what it is given.Fact is that we will always need this in
Renderer
. Which means we'll be doing the same work twice. Why not KISS? We can still choose to makeRenderCache
a public service later.Comment #25
Wim LeersFinally, green patch :)
Comment #26
Wim LeersJust a rebase, conflicts automatically resolved by git. Still applies
Comment #28
Fabianx CreditAttribution: Fabianx for Acquia commentedI am nowadays understanding private services much better than 3 months ago.
It makes absolute sense to make this a private service, but the IS needs some work.
Marking as potential 'rc target' as it would be problematic to not being able to make changes to that service anymore.
Comment #29
Wim LeersI think it's too late to do this now?
Comment #30
dawehnerWell seems so. We should at least mark it as internal?
Comment #31
Wim Leers+1.
Comment #33
Wim LeersA rare case of PIFR being green and DrupalCI being red. Which is right?
Seems like DrupalCI is drunk for once. Re-testing.
Comment #34
Fabianx CreditAttribution: Fabianx for Acquia commentedRTBC - we need a beta evaluation now ...
Comment #36
xjmI think marking something @internal during RC is okay, but check with a committer when adding the tag (and mention who you talked to and the reasoning). Cheers!
Committed and pushed to 8.0.x.