Edge Cache expiring in 1 hour instead of 30 days

Hello. I’m using Cloudflare’s Page Rules to:

  • Ignore (bypass) cache for the /live/ directory and its contents.
  • Edge Cache the whole /static/ directory for 30 days.
  • Edge Cache the rest of the website for 5 days.

This is on the .htaccess file in the root of the website:
Header set Cache-Control "max-age=432000"

This is on the .htaccess file in the static/ directory:
Header set Cache-Control "max-age=2592000"

And this is on the .htaccess file in the live/ directory:
Header set Cache-Control "no-store"

The first page rule works fine: all requests inside the live/ directory are always requested to the origin server (cache is bypassed).

Any other request appears to be cached fine by Cloud Flare, because I get the cf-cache-status: HIT header the 2nd time i request any resources. The problem is that, although the Edge Cache TTL is set for 30 days for the static/ directory and 5 days for the rest of the website, after only 1 hour the resource will return cf-cache-status: MISS again, and the file will be requested from the origin server.

Here you can see the Response Headers of a .png file inside the static/ directory. The age and cache-control: max-age values seem to be right.

accept-ranges: bytes
age: 21
alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400
cache-control: max-age=2678400
cf-cache-status: HIT
cf-ray: 64df5c755e96097d-MIA
cf-request-id: 09ff781d5a0000097db4ac8000000001
content-length: 23783
content-type: image/png
date: Tue, 11 May 2021 23:59:27 GMT
etag: "5ce7-5ba273d732340"
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
last-modified: Sun, 31 Jan 2021 00:23:01 GMT
nel: {"report_to":"cf-nel","max_age":604800}
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=Luh8oHywOboVkiFZOQcHPSAXAKBCGaIAoHNAbJQvKyMJxG19ACdaRtaN%2F6Ql9AtChGsjzI1qHVQAs52vpZydE6%2BV2SnQJ5Trn7QNJWw%3D"}],"group":"cf-nel","max_age":604800}
server: cloudflare
vary: Accept-Encoding

Why isn’t Cloudflare applying a 30 days Edge Cache for this resource (and any other resource as well)? What am I missing? Thanks for your help.

The deffinition of “TTL”
It means “Time To Live” but it is not a guaranteed time. For most files, specially if you are not on Free Plan, your cache file will be keept in cache for as long as you define. But if CloudFlare has a file cached for you on some POP where it never again gets called in a certain amount of time it will purge the cache from this particular POP for freeing these ressources.

It also is very likely that you do get rerouted, since the file is probably not cached on the POP you do get served now you pretty sure hit a miss, while the cached file is still cached on the first POP you got served from.

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