When/How does default worker edge cache TTL expire?

I’m trying to understand how cache gets expired at the edge.

I’m using:

  1. GitHub - cloudflare/worker-sites-template (which uses getAssetFromKV from GitHub - cloudflare/kv-asset-handler: Routes requests to KV assets which supposedly has a 2 day TTL)
  2. a custom domain (so the cache is enabled)
  3. Workers Paid plan

I run wrangler publish, refresh the page on my custom domain, and see the cf-cache-status HTTP header in the response for index.html as MISS. I refresh the page, and see HIT. This of course makes sense. If I refresh again, I get another HIT for index.html… this also makes sense.

However, if I wait a random amount of time, say ~5 minutes, refresh the page, cf-cache-status for index.html is sometimes MISS (often along with a different value for cf-ray). But, the static assets in “worker-sites-template”, e.g. /img/200-wrangler-ferris.gif will have a cf-cache-status of HIT.

So my hypotheses is that a different worker served the request for index.html but didn’t have it cached, hence the MISS. But why did the gif file have a cache HIT? Does some stuff fall out of the edge cache and other stuff does not? How does the logic work? Is it some kind of LRU per datacenter, or per worker?

Images generally the CDN defines as cache persistent. To control the cache granularity the worker should pass cache header, and on the dashboard cache set to respect headers.

Cache is unique within a Colo, but different workers isolates can spawn and be evicted over time. Also, colos can vary frequently.

Thanks adaptive, “isolates can spawn and be evicted over time” makes sense.

Follow-up question, after running wrangler publish it takes ~35s for the change to be live. Is that also normal?

Yes, it takes less than a minute for the Worker code to deploy across all available Cloudflare PoPs (~250 locations), also for the cache to purge if instructed.

Now Cache Purge has been improved, you can read more about it here.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.