CF caching not working for AWS S3 Static hosting

I have configured a domain to serve avatars statically from S3. Because we have many users in different parts of the world, the Cloudflare CDN would be a great way of speeding this up. But unfortunately I can’t get it to work.

I have followed the steps to give all files a CachControl header with a large MaxAge value. Also I have added a first Page Rule with Cache Everything and Edge Caching TTL.

But the request always has a cache MISS. After a few minutes it has a HIT. But when I try again in a few hours it misses again. I can see in the request/bandwith stats that very little requests are being cached, even though almost all traffic on this domain is static.

cf-cache-miss

Really at a loss here. Hope there’s an obvious mistake I made.

Example of a static file with this behaviour:

The first request will always be a MISS if the resource hasnt been cached in that particular datacentre yet. Subsequent requests should be a HIT though. I just sent a request and got an immediate HIT.

As for the caching duration, you can adjust that with page rules and setting the respective values. However resources requested less frequently might still get purged from the cache before that time.

1 Like

Thanks for the answer. What puzzles me is why the number of cached requests is so low. Considering there are only static resources (PNG files) on Amazon AWS. They all have above CacheControl setting.

Is there any way to improve this?

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