How to cache R2 assets forever but not 404s?

I'm considering using R2 for a project for user uploads. I am testing it now and I created a bucket, made it public, and added a custom domain (because I wanted the CDN caching). I noticed the Cache-Control header wasn't that long. Ideally the assets would be cached forever / a year at least (aside from 404s). I've been playing around with "Cache rules" and I can't seem to get it right. Any ideas?
2 Replies
adam
adamOP6mo ago
This is my current cache rules config. It is returning a Cache-Control: max-age=... for 404s. However, if I then add an image to the bucket matching that name and do a normal browser refresh, it does actually load the image (so it doesn't use a cached 404). I'm not sure why the 2nd response is a 200. Maybe it's related to ETags?
No description
adam
adamOP6mo ago
I guess it's in an acceptable state now but I'd still like if someone could please look at this
Want results from more Discord servers?
Add your server