Cloudflare and cloudfront show cache hit

Our setup is static files like images, txt, json, video are stored in AWS S3 buckets. We then have cloudfront distributions in front of these buckets with cnames tied to certs provided by Cloudflare. We then have Cloudflare DNS pointing to these cloudfront distributions. We also have page rules with “Cache Level: Cache Everything, Edge Cache TTL: a month” with the url “OurWebSite/”.

The issue is when inspecting files everything looks good except we show in the response headers the following (removed some lines to show issue):
access-control-max-age: 3000
age: 5774
cache-control: max-age=3600
cf-cache-status: HIT
server: Cloudflare
status: 304
via:1.1 (CloudFront)
x-cache: Hit from cloudfront

It looks like both Cloudflare shows a hit but then passes on the cloudfront which shows a hit. This matches up with logs in cloudfront and our AWS bill which shows dramatic cloudfront usage. I verified one .json file here: and it showed a hit. I found this topic “inexplicable-caching-of-content-type” (can’t post link due to being new user) which was resolved by purging all of cloudfront cache but that did not resolve our issue.

Please keep in mind that CloudFlare is no normal CDN and does have a lot of different POPs

If your File is cached in in one of them, and someone requests the site from another location it will ofc hit the CloudFront Cache as this particular POP does not have the file cached already.

Means after a little warmup there should be nearly no hits anymore ion CloudFront.

Also the header will always show “x-cache: Hit from cloudfront” as cloudflare also caches/saves headers from the system behind it.

Pls also provide some more infos.
What file have this header infos been from?

1 Like

That file was served from Cloudflare’s cache. No request to the origin would be made for an object which returned a hit in our cache regardless of the origin source/type.

Also whatever object this is has a 5 minute TTL

This page is what we’re testing with TFT Champion Stats then inspect and any of the JSON files.

Doesn’t “cache-control max-age=3600” mean the ttl is 60 minutes not 5? Not sure which entry is showing a ttl of 5 minutes.

The file champions.json is the most pulled from cloudfront from that URL.

Well if you use CF there are two TTL’s

  1. “Browser Cache TTL” how long a User keeps the File localy cached on his machine
  2. “Edge Cache TTL” how long CF caches the File untill it revalidates it.

For me it seems your Edge Cache TTL is not high enough for your needs.
You can solve this by (for example) a Pagerule:

Match:*.js* (this will match for .js and json, but greater Edge Cache TLL is better)

Edge Cache TTL: 1month

This keeps the File stored statically in every CF POP it once get requested once.

Pls also keep in mind clearing the from CF Cache once you changed the settings

Hope this helps

This topic was automatically closed after 14 days. New replies are no longer allowed.