# Cache

A temporary store that reuses previously obtained or computed data to reduce latency, network traffic, or work on future access.

- Type: term
- Domain: Engineering & architecture
- Level: Foundational
- Last reviewed: 2026-09-23
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/cache/>)

## What 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.

## Why 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.

## When 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.

## How it works

1. Choose what to cache, where to store it, and which request attributes form a safe cache key.
2. On lookup, return a matching fresh entry and record a cache hit.
3. On a miss or stale entry, retrieve or compute the authoritative value and optionally validate an existing copy.
4. Store the result with freshness, privacy, variation, size, and eviction rules.
5. Invalidate or refresh entries when state changes and protect origins from simultaneous refill traffic.
6. Monitor hit rate, latency, staleness, evictions, errors, and origin load against product outcomes.

## A 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.

## Where 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.

## Visualization

[View the visualization on the website](<https://wiki.soroush.uk/topic/cache/#visualization-cache>)

## Sources

1. [HTTP Caching \(RFC 9111\)](<https://www.rfc-editor.org/rfc/rfc9111>) — RFC Editor · Internet Standard
2. [HTTP Caching](<https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Caching>) — MDN Web Docs · Official technical documentation

## Related topics

- [HTTP](<https://wiki.soroush.uk/topic/http/>)
- [Content Delivery Network \(CDN\)](<https://wiki.soroush.uk/topic/content-delivery-network/>)
- [Non-Functional Requirements](<https://wiki.soroush.uk/topic/non-functional-requirements/>)
