Workers fetch cache (tiered caching) - How to handle conditional caching?
I have a use-case where we'd like to utilize tiered caching instead of the cache API to help shield our origins from requests, but I'm struggling to replicate the same logic using the fetch cache. Our worker essentially acts as a reverse proxy, handling internal routing & query parameters to the origins (multiple servers).
This is a very slimmed down version of our logic using the cache API:
However, with the fetch cache, we don't have the same control as far as I can tell.
Is there any way to work around this that doesn't involve using the cache purge API from within the worker? (250k purges per day would quickly be hit)
1 Reply
AFAIK, you will need to use both Workers and your origin to use fetch cache correctly.
caches.default.delete
is a Cache API operation, and it is local to where the Worker ran. It won't work with Tiered Cache/Fetch Cache.
One way to do it:
And then make your Origin send the necessary headers to make this work, for example, Cloudflare-CDN-Cache-Control
. Fetch should respect it, not caching private content, etc.