Caching Strategies with Redis

Harry · 13 Sep 2026 · 2 views

Cache-Aside (Lazy Loading)

  1. Ask Redis for the key.
  2. On miss, load from the database.
  3. Write the value back with a TTL.
  4. 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-lfu

With 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.

Cache-aside with Redis

Share this post:

Comments (0)

Please login or register to comment.