How CF cache works with cloudflare.

I am trying to figurout how exacly CF cache works with workers. I read that workers are running in front of the cache - so my first assumption was that all request will hit worker even if they are cached but this does not seems to be true First of all, my CF setting is to cache everything, ignore headers for 8 hours. 1. I noticed that sometimes the content is served from cache without hitting workers, My sveltekit middleware config looks like this (screenshot). So i have few question about that: 1. Keeping in mind my CF cache settings cache-control header will be ignored anywah here right? 2. Why sometimes I can notice two situation: - response are directly served from cache - CPU time is 1ms - responses are hitting worker then worker finds that data exists in cache (I see console log - cache HIT in logs) and served from cache through worker Sometimes seems that cache is ignored completely (I see this based on CPU usage for woker - 200ms) , but 8hour of cache did not passed yet. Why is that? My app is running in singel datacenter (Warsaw) and traffic is allowed only from Poland - based on that I would assume that within 8hours period I would traffic only served from cache. But like mention above there is three cases - cache hit from CF - cache hit from worker + cf - data not served from cache even if 8hours not passed Thanks for the help
No description
2 Replies
interpod
interpodOP5mo ago
My domain looks like this
No description
interpod
interpodOP3mo ago
Ok let me give an example 0. My whole domain point to worker 1. I typing GET / 2. Logic is that GET /* returns from worker HTML + sets the CF cache for url /my-playground 3. Typing GET /my-playground - my expectation would be that worker will accept and handle this request but it seems instead of returning HTML (which is that my worker always returns HTML) - it returns the content i set in step 2. Why is that? Yes, I did a test where I removed cache from middleware and added instead to route /* In short the handler would looks like something like this (in pseudcode)
//route for all requests
function GET() {

console.log("execute");


if(url === '/') {
cache.set(new Request("https://mydomain.com/my-playground"), response)
}

return html
}
//route for all requests
function GET() {

console.log("execute");


if(url === '/') {
cache.set(new Request("https://mydomain.com/my-playground"), response)
}

return html
}
So for GET https://mydomain.com/my-playground instead of getting "execute" in CF events logs I am getting content I set in code any ideas?

Did you find this page helpful?