Show in graph
SYS

Software → System Design

Cache

A storage layer that keeps frequently accessed data closer to where it is needed.

Cache diagram

Motivation

Cache solves the problem of repeated expensive work. When data is slow to compute, fetch, or read from storage, a cache keeps a nearby copy so future requests can be served faster.

Where it fits

Cache belongs in system design because it changes latency, capacity, availability, and consistency. The same idea appears in CPUs, browsers, databases, CDNs, and backend services.

Mental model

A cache is a fast temporary memory in front of a slower source of truth. The design question is not only what to cache, but also when cached data expires, how it is invalidated, and what happens on a miss.

Subconcepts

LRU Cache

A cache eviction policy that removes the least recently used item first.

LFU Cache

A cache eviction policy that removes the least frequently used item first.

FIFO Cache

A cache eviction policy that removes the oldest inserted item first.

Cache Hit

A request served from cache instead of the original data source.

Cache Miss

A request not found in cache that must be fetched from the origin or backing store.

Cache Invalidation

Removing or updating cached data when the original data changes.

Cache Eviction

Removing entries from a cache when capacity or policy requires it.

Cache Policy

The rules that decide what is cached, when it expires, and what is evicted.

Common mistakes

  • Treating the cache as the source of truth.
  • Caching without an invalidation or expiration strategy.
  • Ignoring stampedes, stale data, and memory limits.

Cache connects to latency, availability, CDN, Redis, database indexes, and replication.