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?
2 Replies
Erisa
Erisa7mo ago
Depending on how you purge it and your request pattern, you might see REVALIDATED or EXPIRED instead. Each type of purge has the "Resulting cache status" documented on its page, e.g. https://developers.cloudflare.com/cache/how-to/purge-cache/purge-everything/#resulting-cache-status A brand new never-before-seen asset will always start with a MISS though
davidbarratt
davidbarrattOP7mo ago
Though in those scenarios: - REVALIDATED would be that the resource hasn't changed (at least according to the origin) and thus there is no new metadata to store. - EXPIRED for my purposes would be the same as HIT because the resource hasn't been updated, but on the next request for that resource, I should see a MISS right? Thanks for your help! @Erisa | Support Engineer any more thoughts?
Want results from more Discord servers?
Add your server