← Back to Node.js performance mapcache
📦
Node.js Performance
Cache Aside TTL
Use Redis cache-aside with TTL and stampede protection.
Detailed Description
Cache-aside means the application checks cache first, loads from the source on miss, then stores the result with a TTL. It is simple and works well for read-heavy data.
Stampede protection prevents many concurrent misses from all hitting the database at once. TTL choice matters: too short causes misses; too long risks stale data.
Mental Model
check cache -> miss? dedupe inflight -> fetch DB -> setex
When To Use
- ->Frequently read data changes occasionally
- ->DB is overloaded by repeated reads
- ->Many users request the same missing cache key at once
Tools: ioredis, cache-manager, lru-cache, stampede protection
cache-aside.js
Live Editor
Loading...
Output
Run code to see output...