Why set max-age to 0 in ViewsReferenceFieldFormatter::viewElement()?
See, http://cgit.drupalcode.org/viewsreference/tree/src/Plugin/Field/FieldFor...
Instead, why not let the view bubble up it's cache tags?
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | viewsreference_remove-max-age_2912148_9.patch | 681 bytes | jasonawant |
Comments
Comment #2
NewZeal commentedWhat do you mean by let it bubble up?
Comment #3
jasonawantHi,
Thanks for the follow-up question.
Drupal 8's render pipeline allows each render array to define it's own cache metadata. Drupal 8 will take that information and then push it up the render tree, which ultimately is added to the response header.
See the following docs and articles
I noticed that setting max-age was removed in the 2.x version, see http://cgit.drupalcode.org/viewsreference/tree/src/Plugin/Field/FieldFor....
Comment #4
NewZeal commentedSo if I remove the cache setting, will cache be unset by default and only be set if something hooks into it and deliberately sets it?
Comment #5
jasonawantI can't think of any reason why it would be set here.
I'm not sure what you mean by "unset" in your question.
By not setting it, I think max-age would likely not be set at all, and instead cache-tags will be set from the view and its rendered entities. Views uses cache tags caching by default. For example, when a view renders the latest 3 article nodes, it will include cache tags for each rendered node entity, as well as any files or other referenced entities used in the article node, along with node_list cache tag.
Read about cache tags here > https://www.drupal.org/docs/8/api/cache-api/cache-tags
And debugging them here > https://www.drupal.org/docs/8/api/responses/cacheableresponseinterface#d...
However, if the view is configured to use time-based caching, I think it will set max-age and it will bubble up to the page rendering.
Read about views cache settings here > https://docs.acquia.com/article/views-caching
In regards to something hooking into it and setting max-age or other cache metadata, that is entirely possible. There are points along rendering pipeline something could do that.
Comment #6
NewZeal commentedOk, based on your advice, I'll remove the cache setting.
Comment #8
NewZeal commentedPushed to dev branch for testing.
Comment #9
jasonawantHello,
Thanks for changing this. I rolled this patch against 1.0, so I did not switch to the dev version at this time.
When testing this change though, Drupal wasn't able to cache the page when setting max-age to 0, now with that removed it is!
Marking RTBC.
Comment #11
rodrigoaguileraShouldn't this issue be closed? I don't quite get what work is left to do
Comment #12
NewZeal commented