Question about caching

Hello, I have some simple questions regarding caching and R2. I have a bunch of static assets for my site (that doesnt really change over time). I use an R2 bucket to store them. I'm also using the cloudflare CDN for caching and I've set the rule as shown in the image. My question is : why when i hit the cloudflare cache, i see the max-age as 14400 (4hour). Is it showing the browser ttl and not edge ttl ? Also how i can be sure that the edge ttl is like 1year (or close too) ,
No description
12 Replies
RedWest
RedWestOP5w ago
No description
RedWest
RedWestOP5w ago
Also: I don't clean the cloudflare cache, but I notice that the number of A and B operations increases slightly when I don't perform any operations. Is this normal? Sorry if my questions are silly, I'm just discovering the world of web development, caching, etc.
Chaika
Chaika5w ago
Yes, Edge Cache TTL isn't shown to you in the response headers and that is showing browser ttl, not edge ttl. You can use the account Trace tool to ensure the url is matching your cache rule, or override the browser ttl in your cache rule as well. Worth noting your assets if unpopular will be evicted far before a year. TTLs just say "you can cache for up to this long", but not a guarantee.
I don't clean the cloudflare cache, but I notice that the number of A and B operations increases slightly when I don't perform any operations. Is this normal?
Actions in the R2 dashboard cause A/B ops. Listing buckets, files, etc
RedWest
RedWestOP5w ago
Oh thanks for these answers it's clearer for me. Last question, if my assets are open often enough (its for a statistical website for video games). Is keeping 4h for the browser cache is good or it is better to set a very long duration like 1 year? worth noticing that these assets wont change
Chaika
Chaika5w ago
Another note: you mention you haven't cleared the cache but ops are still increasing, other then actions in the dashboard also causing them, Cloudflare's cache is not a single uniform entity, there's a cache per Cloudflare Point of Presence/PoP, and Cloudflare has some ~300 PoPs, plus the fact each one will evict if not frequently requested
Is keeping 4h for the browser cache is good or it is better to set a very long duration like 1 year?
For the browser? It depends. Unlike Cloudflare's cache, there's no magical button to clear browser cache, so they truly won't check for that long and won't see any updates. However, each asset is immutable then it doesn't matter
RedWest
RedWestOP5w ago
Thank again for your answer. Also is using R2 storage to store this type of immutable asset is the best alternative CloudFlare has to offer?
Chaika
Chaika5w ago
Depends on what your exact requirements are and costs: https://developers.cloudflare.com/workers/platform/storage-options/
Cloudflare Docs
Choosing a data or storage product. · Cloudflare Workers docs
Storage and database options available on Cloudflare's developer platform.
Chaika
Chaika5w ago
KV can be useful, and potentially faster (Two central stores w/ data, some magic to speed up internally), it's what Cloudflare uses with Cloudflare Pages for web assets, for example. But the main drawbacks are being more expensive then R2 and 25 MB max object size
RedWest
RedWestOP4w ago
ty, i'll check that. Also during this night i had this on the cache report
No description
RedWest
RedWestOP4w ago
I suppose it's some kind of bots or something else. I was wondering if error 404 was counting as A/B operation class for R2
RedWest
RedWestOP4w ago
Seeing that all of these bot requests come from a http1 client. SHould i block HTTP1.1 ? Isnt this protocol mostly used by bots ?
No description
Chaika
Chaika4w ago
It's not unheard of to block or challenge http/1.1 for that reason - Any modern browser will automatically upgrade to http/2 during the connection setup process, but it is heavy handed. Lots of bots are friendly, search engine crawlers, plus some items like websockets can only be established over http/1.1
I suppose it's some kind of bots or something else. I was wondering if error 404 was counting as A/B operation class for R2
Yea that's def bots, would be Class Bs for requests

Did you find this page helpful?