Reusing an earlier answer
A cache stores something that would otherwise need to be fetched or computed again. When a request can use the stored value, it is a cache hit. When no suitable stored value is available, it is a miss. Caching can save work, but correctness depends on knowing when the earlier answer is still appropriate.
HTTP caches are one familiar instance. They store responses associated with requests, subject to rules about when storage and reuse are permitted. RFC 9111 defines the relevant HTTP cache behavior and control fields. Other caches, such as an application lookup table or CPU cache, operate at different layers and should not be treated as interchangeable mechanisms.
Start with the cache key
Imagine a service calculating shipping estimates. The answer depends on destination, package weight, service speed, and the current tariff. If the cache key contains only the destination, a heavy package might incorrectly receive an estimate calculated for a light one. A fast wrong answer is still wrong.
One possible key includes the destination zone, weight band, service tier, and tariff revision. That design can reuse an estimate while keeping different pricing conditions separate. Whether it is sufficient depends on the actual rules. If packaging dimensions also affect the price, they belong in the calculation and in the reuse decision.
Consider personalized results too. A discount available to one account must not accidentally become the answer served to another. Including the right identity context in an application cache can be necessary, while avoiding unnecessary caching of sensitive data may be the better choice in some systems. The key and access policy need to agree.
Freshness is an explicit compromise
A stored value can become stale when its source changes. A time-to-live policy allows reuse for a defined period, accepting some delay in seeing changes. An invalidation process removes or replaces entries when relevant events occur. A revision-based key makes a new version a different cache entry.
In the shipping example, a tariff revision is a natural boundary. In a live inventory display, stock can change repeatedly during a short interval, so a cached count may be suitable as an estimate but unsuitable for final reservation. Decide what freshness the operation requires before selecting the cache policy.
Storage and reuse are different controls
HTTP’s directive names can be surprising. As the MDN caching guide explains, no-cache permits storage but requires validation before reuse; no-store instructs caches not to store the response. A private directive prevents storage by shared caches while allowing a private cache under the applicable rules. These are protocol controls, not a complete privacy architecture.
Validation can ask the origin whether a stored representation is still current, for example using an entity tag. If it is unchanged, the body need not be transferred again. That saves transfer while still requiring communication with the origin. It is different from serving a fresh cached response without contacting the origin at all.
Measure misses as well as hits
A reported hit rate needs context. A cache hitting on many tiny objects might save less work than one that hits on a few expensive computations. Also inspect the cost of a miss, storage used, eviction behavior, and the response when a popular entry expires. Many simultaneous misses can send a burst of work to the source.
Test a cold cache, a typical warm cache, and a source update. Check that the system returns the right value after the update, including for different users and input variants. Caching is useful because it avoids unnecessary repetition, but it is a design of allowable reuse. Read cache locality for reuse at the hardware-memory level and APIs for the service contract a cache must preserve.