a cache rule would work fine to bypass

a cache rule would work fine to bypass all cache for requests which hit the custom domain regardless of where it comes from, just do hostname eq myr2hostname.com, bypass
5 Replies
Whey
Whey•3w ago
Do you have a super simple step by step guide what to do? Because I dont follow here 🤔 I'm a beginner!
Chaika
ChaikaOP•3w ago
Go to the Cloudflare dashboard, under websites, select your domain, then Caching -> Cache Rules -> Create Rule Magic Link: https://dash.cloudflare.com/?to=/:account/:zone/caching/cache-rules/new Select field Hostname eq then put your full r2 hostname, minus any https:// or trailing slashes Then bypass cache
No description
Chaika
ChaikaOP•3w ago
I reread some of the original context for this. It's worth noting: you don't get billed for any cache hits, so cache is generally very good for you. They're pretty cheap at $0.36/ million class b get objects though. In a perfect world, you simply wouldn't reuse object names if they've changed. Images would be referenced/saved by UUID, and every new one is a new uuid, so new cache. Then both you and clients see updates instantly and you still get cache. Anything other then that gets messy/has more tradeoffs. If you don't have full control over your panel/solution though, then it makes sense to either just disable cache all together, or have a separate uncached r2 custom domain, etc
Whey
Whey•3w ago
Thanks for the guide, will give it a try in the morning. Getting late here! 🙂 Thanks for the information too! And you're right maybe I will just edit the system to create a new name every time instead.. But do you know how long the images are cached for by default? And IF I would like to turn of cache or change it for the r2 images, where do I do that? only for the images on my custom domain, not my entire website cache
Chaika
ChaikaOP•3w ago
new name every time instead..
new name in general would work, but uuids/random stuff has the advantage of being unguessable
But do you know how long the images are cached for by default?
If there's no cache control headers at all, 2 hours
And IF I would like to turn of cache or change it for the r2 images, where do I do that?
There's no general r2 image cache, just r2 custom domain cache, which you can configure with cache rules like above. You could change the time by picking "Eligible for cache" and overriding ttl
only for the images on my custom domain, not my entire website cache
The Hostname filter makes the cache rule only effect your r2 custom domain. You could go further and use If Path Ends with jpg or png or gif if images aren't the only thing in the bucket and you want to exclude the other items

Did you find this page helpful?