Skip to content
StackDecode
System Design
7. Caching ArchitectureAnimated

Introduction to Caching

Keeping copies of frequently used data in a faster place.

The idea

A cache trades memory for speed: repeat requests skip slow work such as database reads or computation.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

request streamABFBFADADADFAADAACBDAFcache (4 slots)Alast use 1MISS A is fetched from the databasehit rate 0% (0 of 1)
  • hit
  • current request

A is missing: fetch it from the database and store it.

step:
1
hits:
0
1/22

Eviction policy: least recently used.

Step by step

  1. 1Request arrives
  2. 2Check the cache
  3. 3On a hit return it
  4. 4On a miss load, store, then return

Where it is used

Almost every fast system.

Watch out for

Stale data and cache invalidation.

Related