I’m trying to build an API with workers that also serve files from R2. I would like to make use of CF’s caching as much as possible.
Approach 1
get
the object from the R2 bucket and cache it through the Cache API (https://developers.cloudflare.com/r2/examples/cache-api/
). This appears to the standard approach. The downside is that it doesn’t use tiered caching and only caches at the request data centre.
Approach 2
fetch
the object in the worker from the public R2 bucket and benefit from the tiered caching. The downside is that R2 bucket is public although this isn’t a problem in this particular use case.
My questions
- Is using the tiered caching worth the extra effort when pulling object from R2?
- Would I still need to use the Cache API from the
fetched
object in approach 2 when I want to use the lowest level cache? - Are there other downsides for approach 2, or better ways to approach it?
I would be happy about any insights or ideas.