Caching Strategies with Redis
Harry
· 13 Sep 2026
· 2 views
Cache-Aside (Lazy Loading)
- Ask Redis for the key.
- On miss, load from the database.
- Write the value back with a TTL.
- Serve subsequent reads from Redis.
TTL expires stale entries; the app is the source of truth, so the DB stays consistent.
TTL Policies
CONFIG GET maxmemory-policy
# noeviction | allkeys-lru | volatile-lru | allkeys-lfuWith a maxmemory cap, eviction preserves the hottest keys (LRU/LFU) instead of failing writes.
Cache Consistency
Invalidate on writes: after updating the DB, delete or update the Redis key so readers never serve stale data.
Use It for
- Session storage with TTL.
- Hot query results and API responses.
- Rate limit counters (INCR + EXPIRE).
- Leaderboards and ranking caches.
Key Points
- Cache misses flow to the DB and fill Redis.
- TTL and eviction bound memory and staleness.
- Write-through invalidation prevents staleness.
- Sessions, counters and responses all fit the model.