> So i am expecting for the same request
So i am expecting for the same request with in my window of an hr, the 2nd fetch response would be taken from the cache not go to make another http request correct ?Cache by default is per colo/cf dc, and some Cloudflare Points of Presence even have multiple colos, so you might be routed to a different one/different visitors will certainly be, and get MISS's, plus TTL is just a max and CF may evict it far before then based on access frequency.
if this is the case why for every fetch request i do the worker gets called and returns the response?The worker will always be invocation/run on every request, even if using cache
How can i validate that this is from the cache or not?Check response headers for CF-Cache-Status
10 Replies
Thank you for your response, i tried to check for CF-Cache-Status header and it returns back null .
any idea what might be causing this ?
how are you returning the response? If you're just returning it directly
return fetch(...)
then those headers should be in your response headers in the browser as well, easier to debug withconst modifiedRequest = new Request( env.auth_url, {
method: 'POST',
headers: originalHeaders,
});
// Call fetch with the new request and cache configuration
const response = await fetch(modifiedRequest, {
cf: {
cacheTtl: 3600,
cacheEverything: true
},
});
yes i using the response returned from the fetch but the headers give me an empty objcacheEverything applies to only GET and HEAD
This option applies to GET and HEAD request methods only.
you'd have to manually use the Cache API: https://developers.cloudflare.com/workers/examples/cache-post-request/
Cloudflare Docs
Cache POST requests · Cloudflare Workers docs
Documentation for Cloudflare Workers, a serverless execution environment that allows you to create entirely new applications or augment existing ones …
i adjusted the code to fetch with the get to try things out and it gives the same result.
The fetch result is correct but cf-cache-status is still null
What's the URL to, something on your website or external?
the url is a my worker.dev url
late response but there's no cache on those/workers are always going to run in front of cache
got it . thanks