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?

Comments

jasonawant created an issue. See original summary.

NewZeal’s picture

What do you mean by let it bubble up?

jasonawant’s picture

Hi,

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....

NewZeal’s picture

So 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?

jasonawant’s picture

I can't think of any reason why it would be set here.

I'm not sure what you mean by "unset" in your question.

will cache be unset by default and only be set if something hooks into it and deliberately sets it?

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.

NewZeal’s picture

Ok, based on your advice, I'll remove the cache setting.

  • New Zeal committed 9af27ed on 8.x-1.x
    Issue #2912148: Why set max-age to 0 in ViewsReferenceFieldFormatter::...
NewZeal’s picture

Status: Active » Needs review

Pushed to dev branch for testing.

jasonawant’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new681 bytes

Hello,

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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: viewsreference_remove-max-age_2912148_9.patch, failed testing. View results

rodrigoaguilera’s picture

Shouldn't this issue be closed? I don't quite get what work is left to do

NewZeal’s picture

Status: Needs work » Closed (outdated)