What is the right Cloudflare cache behavior working with Workers?
✅SolvedWorkers
Hi guys, I think I'm pretty confused of my understanding about how CF edge cache works, especially when it works with Workers.
What is the right cache behavior of this Workers code?
// let's say a handler is just returning simple text content, with Cache-Control header like this:function handler(ctx) { return new Response("some content", { headers: { 'Cache-control': 'public, max-age=600, s-maxage=600' } });}
// let's say a handler is just returning simple text content, with Cache-Control header like this:function handler(ctx) { return new Response("some content", { headers: { 'Cache-control': 'public, max-age=600, s-maxage=600' } });}
Let's assume the Cloudflare Cache setting is like this: - Cache eligibility: Eligible for cache - Origin Cache Control: Enabled
I expected that the response should be cached in CF edge cache and include
Cf-Cache-Status: HIT
Cf-Cache-Status: HIT
header because the Origin Cache Control is enabled so the cache should respect the Cache-Control header of the repsonse, but it seems not. It doesn't include the
Based on the behavior described above, it seems that Cloudflare Workers are treated somewhat differently from a typical origin (particularly with respect to caching behavior). Is this correct? And if so, is there any way to make this response cached by cloudflare?
CDN-Cache-Control is a response header field set on the origin to separately control the behavior of CDN caches from other intermediaries that might handle a response. You can set the CDN-Cache-Control or Cloudflare-CDN-Cache-Control response header using the same directives used with the Cache-Control.