Lesson 5 / 32

Caching

Storing hot data closer to the reader to cut latency and load.

Where caches live

Browser, CDN, reverse proxy, application memory, and a shared store like Redis. Each layer absorbs reads so the database sees only the misses.

Write strategies

Cache-aside: app loads on miss, writes DB and invalidates. Write-through: write cache + DB together. Write-back: write cache now, DB later (fast, risky).

Always set a TTL

An expiry bounds staleness and stops a poisoned entry living forever. Add jitter to TTLs so keys don't all expire at once (thundering herd).

Quick check: Which eviction policy removes the entry unused for the longest time?

  • FIFO
  • LRU
  • Random
Answer

LRU — LRU (Least Recently Used) evicts the coldest entry by last access time.