upper icon indicating copy to clipboard operation
upper copied to clipboard

Cache tags not getting added to responses when content is within {% cache %} twig tags

Open RedLucas opened this issue 3 years ago • 4 comments

I've noticed that only get generated and added to the response headers (in my case Cloudflare Cache-Tags) when the Response is a cold cache.

So on first load, the response has all necessary CacheTags headers, but it's possible that the cloudflare cache will be cleared for reasons.

Since Craft's template cache is caching content, any entries that were loaded within the {% cache %} tags no longer get added to the response headers.

I'm seeing this on CraftCMS 3.7.32 and Upper 1.9.1.

I'm not sure that this was always a problem, but perhaps it's a new problem from the 3.7 update?

RedLucas avatar Feb 12 '22 00:02 RedLucas

I guess it was always like this. 🙉 To me, it makes sense to use the Craft/twig template cache and the full-page-cache Upper provides.

I need to investigate the behavior. Hopefully, there is an easy way to deliver cache tags even if you use the {% cache %} tag.

ostark avatar Feb 14 '22 12:02 ostark

It's very possible!

ostark avatar Feb 14 '22 16:02 ostark

You can use Craft's new-ish (as of 3.5) built-in functionality for collecting element cache tags via Elements::startCollectingCacheTags() / Elements::stopCollectingCacheTags() to get a list of tag dependencies for a rendered template

khalwat avatar Jun 16 '22 15:06 khalwat

Related PR: https://github.com/craftcms/cms/pull/11617

khalwat avatar Jul 18 '22 00:07 khalwat