davidbarratt
davidbarratt
CDCloudflare Developers
Created by davidbarratt on 4/28/2024 in #general-help
Is at least one cache MISS guaranteed?
Given the Cache Statuses here: https://developers.cloudflare.com/cache/concepts/cache-responses/ If a resource is purged from the cache, is a worker guaranteed to see at least one MISS before the resource re-enters the cache? Based on the scenarios here: https://developers.cloudflare.com/cache/concepts/revalidation/ it seems like the answer is "Yes"? Or is it possible for it to go from HIT to UPDATING to HIT without ever seeing a MISS ? Basically I'm trying to save some metadata from the origin when there was a cache miss, but I don't want to check save every outbound request, I only want to update D1 when the resource is actually different (or could be different) My hope is that I can have something like:
if (response.headers.get('CF-Cache-Status') === 'MISS') {
// Update metadata for that resource.
} else {
// Served from Cloudflare (`HIT`, `UPDATING`, etc.) or is not cacheable (i.e. `DYNAMIC`)
}
if (response.headers.get('CF-Cache-Status') === 'MISS') {
// Update metadata for that resource.
} else {
// Served from Cloudflare (`HIT`, `UPDATING`, etc.) or is not cacheable (i.e. `DYNAMIC`)
}
Also, the site may or may not use tiered caching and cache reserve, but from the scenarios it looks like the answer should be the same regardless?
5 replies