Caching Strategies
5 min read
Module Overview
What You’ll Learn
- Explain what caching solves, and what it risks if used carelessly
- Use Redis to cache the result of an expensive operation
- Choose a cache invalidation strategy, and explain why invalidation is the hard part
💡 Why this matters: Every database query in this track has hit a real database, every time, even for data that barely changes. Caching skips that work for repeated requests, at the cost of a new problem this module spends real time on, a cache that’s wrong is worse than no cache at all.
What’s Covered
- What belongs in a cache, and what doesn’t, data that’s expensive to compute and doesn’t need to be perfectly fresh.
- Redis, a fast, in-memory data store, set up and used as an application cache.
- Cache invalidation, expiration (TTLs), and explicit invalidation on writes.
- Cache-aside, the most common caching pattern, checking the cache first, falling back to the real source on a miss.
Hands-On
By the end of this module, you’ll have added a working Redis cache in front of a real, expensive operation, with a working invalidation strategy.
Next module: horizontal scaling, running more than one instance of an application, and balancing load across them.