Cache not re-fetching or purging

Hello!

I’m having some trouble understanding why the Cloudflare cache does not fetch content again when the age is greater than s-maxage. All of my cache-control headers are set by my backend server. Here is an example response:

image

Why doesn’t this re-fetch after 15 minutes?

My caching level is set to “Standard.” I have a wildcard on the whole site enabling “Cache Everything.” “Browser Cache TTL” is set to “Respect Existing Headers.” I have not set a Page Rule with “Edge Cache TTL.” My site does not use any cookies.

Another thing I do not understand is that the “Purge Cache” options in the dashboard do not seem to always work. I have tried from multiple devices, with the cache on those devices disabled, but Cloudflare simply doesn’t purge properly even after 15 minutes of waiting. I have tried the “Purge Everything” option as well as specific URLs.

Thanks!

It’s quite possibly because minimum Edge Cache TTL on Free plans is 2 hours. I know it says it respects all headers, but then goes on to say minimum TTL is 2 hours.

@thedaveCA and @eva2000 have experimented with this and have a pretty good idea on how it actually works.

One other thought, has the content actually changed? Cloudflare won’t necessarily download a new copy of the last-modified hasn’t changed, I think. This is more a function of your web server returning a Not Modified and won’t apply to dynamic content, but, for a simple test of a static file, the Age header might not change.

I’m not sure if this applies when you force a cache clear, but I’m pretty sure it applies to the max-age family.

1 Like

What’s strange is that when it does refresh, it does so either 2) after 900 seconds when it is supposed to or b) some other time later, but definitely not as long as 2 hours. Where in the docs do you see the 2 hour minimum? I can’t find it.

Yes, the content has changed and the Last-Modified header has updated accordingly.

My past experience with the “Purge Cache” button is that it always works and clears out no matter the case.

2 different caches - s-maxage controls CF CDN Cache TTL only while max-age and cache control respect origin directives control browser cache. You would need for s-maxage to be lower than max-age browser cache TTL for you to fetch updated content. CF free plan s-maxage CDN Cache TTL min is 2hrs. Pro plan minimum is 1hr. Biz plan min is 30mins. You can use CF Workers to do custom CDN Cache TTL below plan’s min CDN Cache TTL.

1 Like

Yes, and I also manually disabled the cache in my browser to ensure this. I also could see with each request other CF headers changing.

I see. I am still yet to find documentation of this on their support pages, but it must be true. It is annoying that this is not immediately clear or consistent, as the cache seems to sometimes honor the lower cache time and sometimes not. If the reality is that it is something like “2 hours guaranteed, but low-priority/best-effort below that for the Free tier” then that is really nice as well but should also be documented.

It would be great if this was on all of the pages that describe the cache headers and Edge TTL settings, such as this one:

This also still doesn’t explain why the “Purge Cache” button doesn’t always work. If this applies to that too then there seriously should be something in that UI to say so. I should note that the purge cache issue also also affecting other files I am serving, and those have higher cache times.

Ah, that’s a good workaround. I also realize now that if I can purge the CDN cache of specific files via API then that also works and is technically the most efficient option.

Edge Cache TTL Specify how long to cache a resource in the Cloudflare edge network. Edge Cache TTL only takes effect when included as a setting in a Page Rule that also sets Cache Level to Cache Everything . Edge Cache TTL isn’t visible in response headers. The minimum Edge Cache TTL depends on plan type:

Free - 2 hours
Pro - 1 hour
Business - 30 minutes
Enterprise - 1 second

A purge cache can take up to 30 seconds to take affect. Also make sure you don’t have any origin server side caching in play too as all that would do on CF cache purge, is just hit origin cached version.

Aha, I see. Though this is on a page about Page Rules…not caching specifically. Not very intuitive.

Yes, I double-checked that the server was indeed serving new content, and I waited as long as 15 minutes. Sometimes it just never re-fetches it seems. Nothing appears in my server access logs either.

For that, you’d probably need to contact CF tech support to see if they can look at it from their end.

I’m not sure if this applies when you force a cache clear, but I’m pretty sure it applies to the max-age family.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.