| license | Apache-2.0 |
| name | cache-strategy-invalidation-expert |
| description | Redis caching patterns, cache-aside, write-through, TTL strategies, and invalidation. Activate on: caching, Redis, cache invalidation, cache-aside, write-through, TTL, CDN cache, stale-while-revalidate. NOT for: CDN/reverse proxy setup (use api-gateway-reverse-proxy-expert), database query optimization (use data-warehouse-optimizer). |
| allowed-tools | Read,Write,Edit,Bash(npm:*,npx:*,redis-cli:*) |
| category | Backend & Infrastructure |
| tags | ["caching","redis","invalidation","performance","ttl"] |
| pairs-with | [{"skill":"api-rate-limiting-throttling-expert","reason":"Redis powers both caching and rate limiting"},{"skill":"websocket-realtime-expert","reason":"Cache invalidation can trigger real-time updates"},{"skill":"multi-tenant-architecture-expert","reason":"Cache keys must be tenant-scoped in multi-tenant systems"}] |
Cache Strategy & Invalidation Expert
Design and implement caching architectures using Redis, application-level caching, and CDN layers with reliable invalidation strategies.
Activation Triggers
Activate on: "caching", "Redis cache", "cache invalidation", "cache-aside", "write-through", "TTL", "stale-while-revalidate", "cache stampede", "cache warming"
NOT for: CDN/proxy configuration → api-gateway-reverse-proxy-expert | Database query tuning → data-warehouse-optimizer | Connection pooling → database-connection-pool-manager
Quick Start
- Identify cache candidates — read-heavy, expensive to compute, tolerant of staleness
- Choose pattern — cache-aside (most common), write-through (consistency), write-behind (performance)
- Set TTL strategy — short TTL for volatile data (60s), long TTL + event invalidation for stable data
- Prevent stampede — use probabilistic early refresh or mutex lock on cache miss
- Monitor hit rate — target >90% hit rate; below 70% means your cache strategy is wrong
Core Capabilities
| Domain | Technologies |
|---|
| In-Memory | Redis 7.4+, Valkey, DragonflyDB, KeyDB |
| Application | Node LRU cache, Cacheable, unstorage |
| HTTP/CDN | Cache-Control, stale-while-revalidate, Surrogate-Key |
| Multi-Layer | L1 (in-process) → L2 (Redis) → L3 (CDN) |
| Invalidation | Event-driven purge, TTL, tag-based (Surrogate-Key) |
Architecture Patterns
Cache-Aside with Stampede Prevention
import { Redis } from 'ioredis';
const redis = new Redis();
const LOCK_TTL = 5;
cacheAside<T>(
: ,
: ,
: <T>
): <T> {
cached = redis.(key);
(cached) .(cached);
lockKey = ;
acquired = redis.(lockKey, , , , );
(!acquired) {
( (r, ));
(key, ttl, fetcher);
}
{
data = ();
redis.(key, .(data), , ttl);
data;
} {
redis.(lockKey);
}
}