Fetch() cache behaviour

With the following, the Response 's cf-cache-status header is BYPASS. I was expecting to see cache headers for the specified time instead. url is a URL to a third-party API. I have a change to the data on the third party service, triggered the worker within seconds, and I saw the change immediately - I was expecting it to stay cached. I need to verify how to cache these, as it's implied in the docs it should work.
fetch(url, {
method: "GET",
cf: {
cacheEverything: true,
cacheTtl: 30,
},
headers: {
"Content-Type": `application/json`,
},
});
fetch(url, {
method: "GET",
cf: {
cacheEverything: true,
cacheTtl: 30,
},
headers: {
"Content-Type": `application/json`,
},
});
In case it matters, I am on a paid worker plan. I am using a workers.dev subdomain. The related website in the account is on the Free plan (I am not using it for a custom domain/route for the worker). I am testing this via Wrangler.
4 Replies
Hello, I’m Allie!
workers.dev doesn’t have caching. You need to use a custom domain
Paul Wong-Gibbs
Paul Wong-GibbsOP2y ago
Thank you - I'll use a custom domain. Then this should work? Once on a custom domains, are the minimum TTLS for this per the Edge Cache TTL table on https://developers.cloudflare.com/cache/about/edge-browser-cache-ttl ?
Hello, I’m Allie!
Yeah, that should apply there You might be able to bypass it by invoking the Cache API manually, and using cache headers
Paul Wong-Gibbs
Paul Wong-GibbsOP2y ago
Thank you very much ❤️
Want results from more Discord servers?
Add your server