Cache
A temporary store that reuses previously obtained or computed data to reduce latency, network traffic, or work on future access.
Download Markdown (.md)Soroush’s Product Wiki · https://wiki.soroush.uk/topic/cache/
01What it means
A cache stores a reusable copy of data closer to where it will be needed or in a faster form. A cache lookup uses a key; a hit can serve stored data, while a miss retrieves or computes data from an authoritative source. Freshness, validation, eviction, and invalidation govern reuse.[1][2]
- RequesterLooks up by key
- CacheHit serves · miss continues
- Authoritative sourceRetrieves or computes
Store eligible result, then return it
Keys, freshness, validation, eviction, and invalidation determine safe reuse.
02Why it matters
Effective caching can make products faster, absorb traffic spikes, lower infrastructure cost, and reduce load on dependencies. Incorrect caching can expose private data, serve stale results, hide changes, and turn invalidation or synchronized misses into incidents.
03When to use it
Cache data that is expensive to retrieve or compute, requested repeatedly, and safe to reuse for a defined period or until validation. Avoid or tightly control caching for highly sensitive, rapidly changing, low-reuse, or strongly consistent data where stale results cause unacceptable harm.
04How it works
- Choose what to cache, where to store it, and which request attributes form a safe cache key.
- On lookup, return a matching fresh entry and record a cache hit.
- On a miss or stale entry, retrieve or compute the authoritative value and optionally validate an existing copy.
- Store the result with freshness, privacy, variation, size, and eviction rules.
- Invalidate or refresh entries when state changes and protect origins from simultaneous refill traffic.
- Monitor hit rate, latency, staleness, evictions, errors, and origin load against product outcomes.
05A practical example
A product catalog caches public item details for five minutes and varies responses by language. Price changes trigger invalidation, conditional requests revalidate stale entries, and randomized refresh timing prevents thousands of popular items from expiring simultaneously.
06Where it breaks
Caches create another stateful layer whose contents may lag the source of truth. Memory and invalidation cost can outweigh benefits, low hit rates waste resources, and failures can amplify into cache stampedes or expose one user's response to another.
Common mistakes
- Using an incomplete cache key that mixes users, permissions, languages, or representations.
- Treating expiration as a complete invalidation strategy for correctness-critical changes.
- Measuring hit rate without checking staleness, user latency, cost, or origin protection.
- Allowing many expired entries to refill concurrently and overload the source system.
07Sources
- HTTP Caching (RFC 9111)RFC Editor · Internet StandardHTTP Caching (RFC 9111)
- HTTP CachingMDN Web Docs · Official technical documentationHTTP Caching