Caching
A cache is a small, fast store that keeps copies of data you’ve used recently or often, so you don’t have to fetch it again from somewhere slower, like keeping your most-used tools on the workbench instead of in the shed. Caches are everywhere: inside the CPU, in your browser, in CDNs, and in services like Redis sitting in front of a database. Because space is limited, an eviction policy decides what to throw out, often the least recently used item. The harder problem is invalidation: when the real data changes, cached copies are stale until they expire or are deleted. Expiry has its own trap, the stampede, where a popular entry expires and thousands of requests hit the database at the same moment.
In this lesson: A hit-rate graph with an eviction-policy toggle. Break-it: a TTL expiry causes a stampede.