Caching Fundamentals

A cache lives or dies by one number: its hit rate. Every cache access is a small bet — that the data will be there (a hit, served fast) rather than missing (a miss, served slow, plus the overhead of caching it). Whether caching helps at all comes down to how often that bet pays off, and understanding hits, misses, and hit rate — and what you should and shouldn't cache — is the foundation of using caches effectively. Get these fundamentals right, and the rest of caching makes sense.

Building on why caching exists, this post covers the fundamentals — the mechanics every cache shares: hits and misses, the crucial hit rate, how a basic cache works (the lookup flow), and what makes data cacheable (what to cache and what not to). These concepts underlie all the specific caching topics that follow (eviction, invalidation, patterns, distributed, web). Understanding them is understanding how caches actually behave.

Hits and misses

The fundamental events in any cache are hits and misses — whether requested data is found in the cache:

   Cache read:
     check cache → HIT?  → return cached value (fast)
                 → MISS? → fetch from source (slow) → store in cache → return

Hits (found, served fast — the benefit) and misses (not found, fetched slowly and cached — the cost) are the fundamental cache events, with the basic flow being check-cache → hit-or-miss. The balance of hits to misses determines whether caching helps — which is measured by the hit rate.

Hit rate: the key metric

The single most important cache metric is the hit rate — the fraction of accesses that are hits — because it determines whether (and how much) caching helps:

Hit rate (hits / total accesses) is the key cache metric — it determines whether caching helps (high hit rate = effective, low = ineffective or harmful), so maximizing it is the central goal, driven by locality, cache size, and eviction policy. Measuring and optimizing hit rate is fundamental to caching. Achieving a high hit rate starts with caching the right things.

What to cache

A high hit rate requires caching the right data — and knowing what makes data a good caching candidate is fundamental:

What to cache: data that’s frequently accessed (hot — for hit rate), expensive to obtain (for benefit per hit), and staleness-tolerant (for feasibility) — the best candidates are all three (reused, costly, tolerant). Caching the right data (not everything) is how you achieve a high hit rate and real benefit. Equally important is knowing what not to cache.

What not to cache, and cache sizing

The complement — what not to cache, and how cache size matters — completes the fundamentals:

Caching fundamentals — hits (fast, the benefit) and misses (slow, the cost), the hit rate (the key metric determining caching’s value, maximized by caching hot/expensive/tolerant data in an adequately-sized cache), and the bounded-cache reality (can’t cache everything, hence eviction) — are the foundation of all caching. Cache the right data for a high hit rate, and know what not to cache. Next: eviction policies — deciding what to keep when the cache is full.

Key takeaways

Further reading

Sources & References

The key cache metric
Hits, misses, and caching basics