Lesson 13 / 18

Cache Invalidation

Keeping cached data from going stale after a write.

Two strategies

Let a TTL expire it passively, or actively delete the key the moment the underlying data changes — the second is fresher but needs discipline everywhere data is written.

Delete on write

After updating the source of truth, remove the stale cache entry — the next read will repopulate it.

# after UPDATE products SET price = 799 WHERE id = 501
DEL product:501