Cache Rules in front of worker
Hello - I have an app deployed to a worker, and I'm setting cache headers on my responses.
I'm not able to get cloudflare to cache any of my responses, it seems to always bypass and run the worker. I have a cache rule on to make everything eligible for caching, and trace shows me the rule hits, but I never see the cf-cache-status header - rsc.wesbos.com is an example page.
Is it not possible to use a worker as an origin and cache it's outputs with a header?
6 Replies
Correct, Workers always run in front of cache.
okay, so the only way to do it is via cache bindings?
The only way to interact with cache? Fetch, KV api, etc have cache built into them
What are you trying to do?
Workers run faster than cache, so it doesn't make sense to cache workers generated responses which are static.
Fetch runs through your zone config as normal, can override cache/cache via it
KV has cache built in which is quicker than cache api
If you're using Workers Static Assets, they also have their own cache layer (they use KV and kv normal cache)
trying to cache the rendered output of a page - I am caching data with KV already but I want to just have the entire HTML page cached and not even make a worker request
ah ok, yea that's a reasonable use case for the cache api, just can't skip the worker running as a whole. Workers are stupid quick though, checking and returning from cache should be like ~1-3ms cpu time, if not less as more requests hit it.
ah yeah, im using Waku so im hoping I can access that in the middlware. Will try. Thank you