AlgoViz

Caching Strategies and Eviction

medium 25 min

Place fast memory between applications and persistent storage to slash read latency and protect databases.

When it comes up

The moments this idea belongs in a design interview, and the moments it does not.

Signals

When to bring it up

You hearSayBecause
Read-heavy, 100 to 1Cache-aside with a TTLMost reads repeat
The database is at its limit for readsCount repeated reads first, then cache themA cache only helps with repeats
Users everywhere, public pagesA CDN in frontNear copies cut the distance
Must be exactRead the database for that decisionA copy can be old
Millions of writesA cache for reads will not helpTalk about batching or partitioning

Options

Compare your moves

Product pages are slow and the database is busy. What do you do?

BreaksCache everything forever
How
Every query result is stored with no expiry.
Limit
Old prices stay, memory fills, and nobody knows which keys to delete.
Choose when
Only for data that truly never changes.
WorksCache pages for five minutes
How
A TTL and nothing else.
Limit
A price can be five minutes old, and hot pages expire for everyone at once.
Choose when
The business accepts five minutes.
StrongFix the query, then cache-aside with delete and TTL
How
Add the missing index, cache product rows, delete on change, keep a TTL, one refresher for hot keys.
Limit
More moving parts, and a rare stale set remains until the TTL.
Choose when
Reads repeat and a short delay is acceptable.