← Backend Performance & Scaling learning pathBackend Performance & Scaling · Module 4 of 8
Caching
Remember answers so you do not compute them again.
📖 Key ideas
- A cache keeps recent results in fast memory, such as Redis, to avoid repeating slow work.
- Cache-aside: check the cache, and on a miss read the database and store the result.
- Every cached item needs an expiry (TTL) or a clear rule for when it is invalidated.
- Cache data that is read often and changes rarely; do not cache per-user secrets carelessly.
- Watch the hit ratio: a cache that is rarely hit only adds complexity.
💡 Real-life example: A cache is like a shopkeeper keeping the 20 best-selling items on the front counter instead of walking to the godown for every customer.
Cache hitThe answer was found in the cache
TTLTime to live: how long a cached item stays valid
Cache-asideRead cache first, fill it from the database on a miss
InvalidationRemoving or updating stale cached data