Hits, Misses, and Freshness
When a cache receives a request, it checks to see if the response has already been cached. If not, we say the request is a cache miss, and the request is forwarded on to the origin server. Cache misses occur for objects that have never been requested previously, objects that are not cachable, or objects that have been deleted to make room for new ones. It’s common for 50–70% of all requests to be cache misses.
If the object is present, then we might have a cache hit. However, the cache must first decide if the stored response is fresh or stale. A cached response is fresh if its expiration time has not been reached yet; otherwise, it’s stale. Fresh responses are best because they are given to the client immediately. They experience no latency and consume no bandwidth to the origin server. I’ll call them unvalidated hits. Stale responses, on the other hand, require validation with the origin server.
The purpose of a validation request is to ask the origin server if the cached response is still valid. If the resource has changed, we don’t want the client to receive a stale response. HTTP also calls these conditional requests. The reply to a conditional request is either a small “Not Modified” message or a whole new response. The Not Modified reply, also known as a validated hit, is preferable because it means the client can receive the cached response, which saves on bandwidth. A validated miss, where the origin server sends an updated response, is really ...
Get Web Caching now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.