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.
- 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
- 1Request arrives
- 2Check the cache
- 3On a hit return it
- 4On a miss load, store, then return
Where it is used
Almost every fast system.
Watch out for
Stale data and cache invalidation.