System Design
7. Caching ArchitectureAnimated
Least Recently Used (LRU)
Evict the entry unused for the longest time.
The idea
Assumes recently used items will be used again. Keeps a recency order and removes the oldest.
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
- 1On access move the item to the front
- 2When full evict from the back
- 3New items go to the front
- 4Hot items stay
Where it is used
General purpose caches.
Watch out for
A one-time scan of many keys can flush useful entries.