Cache expiring before set TTL

Hi,
I’m using Cloudflare to cache a few static websites hosted in AWS S3, but I’m experiencing some unusual behaviour with one of them (https://cloudsecdocs.com/)

Caching on this website is quite poor, and I can’t really figure out what’s not working as expected, as the same setup for other websites works like a charm.

Details:

  • DNS is being proxied via Cloudflare
  • Caching Level: Standard
  • Browser cache TTL: 8hours
  • Page rules:
    • Match: *cloudsecdocs.com/*
    • Cache Level: Cache Everything
      • Edge Cache TTL: 7 days

When testing (CF-Cache-Status),
I can confirm that the first attempt is always Expired.
After this, resources gets cached for a few minutes (~30mins, way below the TTL of 8hours), then are back to Expired.

Can anyone help me understand what am I missing please?
Thanks!

There are many, many threads on this. Basically, infrequently used files will get evicted early. Especially one-hit-wonders. Edge Cache TTL is more of a “how long is it safe to cache this” setting, not a “how long should we cache this.”

1 Like

Hi, thanks for your reply!

I see, but this, for example, affects even the homepage itself (not a one-hit-wonder).
As said, it is a completely different behaviour than what I see with other static websites, and I’d like to understand what I could do to mitigate it.

You have Cache-Control set to 28800.

Yes, to my understanding that reflects the browser cache TTL of 8 hours?

Sorry, correct, that would be 8 hours. My original reply still stands.

Remember that every edge node has many independent caches. So as far as any server is concerned, any resource is a one-hit wonder if another user doesn’t request that URL through that same exact path (POP → Edge Node) within a certain amount of time.

I totally see your point, and I agree on that behaviour.

What strikes odd to me is that even if I request the homepage from my same exact IP after 30minutes, I will still get an Expired

This is how it looks like for the past month:

Just because you’re on the same IP address, it doesn’t mean you’ll hit the same edge server the second time. It also often takes several hits before a server decides it’s not a one hit wonder.

testing at HTTP Header Checker - Check HTTP Response Headers With curl | KeyCDN Tools shows age header at age: 7609 >126 minutes which is age of CF CDN cached file - so it does cache longer but cache is per CF datacenter

How are you testing cf-cache-status header ? Only via cf-cache-status.net ? try other tools as well

HTTP/2 200
date: Mon, 05 Apr 2021 15:23:42 GMT
content-type: text/html
set-cookie: __cfduid=d475ac3e41a4dac63f12975af06d162b61617636222; expires=Wed, 05-May-21 15:23:42 GMT; path=/; domain=.cloudsecdocs.com; HttpOnly; SameSite=Lax; Secure
x-amz-id-2: BvPZcamwNIjIW80uj3U0Neb98WkkeQxPM6BOOSE68DCZP6udBY1S1CwvjvmpSeUoXpCrUEuU2fk=
x-amz-request-id: 8T7HYP46R59Y7DGJ
last-modified: Sun, 04 Apr 2021 15:35:31 GMT
cache-control: max-age=28800
cf-cache-status: HIT
age: 7609
cf-request-id: 09443afdf20000c2b327883000000001
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
report-to: {"group":"cf-nel","endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=WXJ5maYBuDt6dnUDLuI6PjeiP58u7CoHq89IZUfMzimY80J3wBAXZteav7xGwubqq4bNRzpBFwGB%2Bmbl%2FRmfGT6l1u%2B%2B1zmlOYUD2T%2FVlUBYVmtdKSKUHCRrCdG1"}],"max_age":604800}
nel: {"max_age":604800,"report_to":"cf-nel"}
vary: Accept-Encoding
server: cloudflare
cf-ray: 63b3c7765f77c2b3-FRA
content-encoding: br
alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400

dig deeper into cache analytics based on status codes and query strings and filter to see if non-200 HTTP status codes are pulling down your cache hit rates i.e. if automated bots are hammering your 404 not found pages - which would not be counted as a cache hit

Sadly nothing stands out.
It still bugs me since I managed to achieve a good caching ratio (>90%) for similar static websites.

Any tip would be greatly appreciated.

well keycdn curl testing shows your front page has CF CDN cache age of age: 112251 which is 31+ hrs in cache which so far agrees with your Edge Cache TTL of up to 7 days

HTTP/2 200
date: Tue, 06 Apr 2021 20:27:44 GMT
content-type: text/html
set-cookie: __cfduid=db260112349aa2b85bfb4ece21cfd1b4b1617740864; expires=Thu, 06-May-21 20:27:44 GMT; path=/; domain=.cloudsecdocs.com; HttpOnly; SameSite=Lax; Secure
x-amz-id-2: BvPZcamwNIjIW80uj3U0Neb98WkkeQxPM6BOOSE68DCZP6udBY1S1CwvjvmpSeUoXpCrUEuU2fk=
x-amz-request-id: 8T7HYP46R59Y7DGJ
last-modified: Sun, 04 Apr 2021 15:35:31 GMT
cache-control: max-age=28800
cf-cache-status: HIT
age: 112251
cf-request-id: 094a77b44b00004e37e43d4000000001
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
report-to: {"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=ScsO%2FLQEj5J3e%2BOmLquVFu0ZJ75g91EfxRICWZx%2BZPxu9QgGbwhQeb3H2wclrPFfBFGViz4nOVt2QN3Revn4WuMw%2FHmSWLf4temPDDoaMncKpi1ntECRz1kEE7LQ"}]}
nel: {"max_age":604800,"report_to":"cf-nel"}
vary: Accept-Encoding
server: cloudflare
cf-ray: 63bdc233a9f24e37-FRA
content-encoding: br
alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400
time_namelookup: 0.016053
time_connect: 0.016792
time_sslconnect: 0.079615
time_pretransfer: 0.079820
time_redirect: 0.000000
time_starttransfer: 0.094072
---------
time_total: 0.094571

are you using web traffic analytics or cache analytics ? 2 different tab/pages

This is cache analytics page filtered on path /

if I filter for 403 status requests, they’re not cache hit

image

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