Claude Code: save it as .claude/skills/caching-strategies/SKILL.md
Cursor: save it as .cursor/rules/caching-strategies.md
Codex: save it as .agents/skills/caching-strategies/SKILL.md
ChatGPT, Gemini and other assistants: paste it into custom or project instructions
Skill file
Caching Strategies
When to use
Choosing a caching pattern for a new feature (cache-aside, write-through, read-through)
Designing Redis key naming and data structure selection
Building cache invalidation logic that stays consistent under writes
Setting TTLs that balance freshness with database load
Preventing cache stampede on high-traffic cache misses
Configuring CDN headers for static assets and versioned files
Evaluating whether to use Redis vs Memcached
Setting up cache hit rate monitoring and eviction alerts
Core principles
Pattern before implementation — cache-aside, write-through, and write-behind have different consistency trade-offs; pick deliberately
TTL jitter is mandatory at scale — synchronized expiration = thundering herd; add 10-30% random variance
Hit rate is the only real metric — target >90%; anything lower means either wrong keys or wrong TTLs
Stale is often fine — serve stale data while revalidating in background rather than blocking on a miss
Cache is not storage — set maxmemory-policy allkeys-lru and accept eviction; anything that can't be lost belongs in the database
Reference Files
references/patterns-redis-invalidation.md — four caching pattern descriptions (cache-aside, write-through, write-behind, read-through), Redis data structure selection guide, connection management, key naming conventions, and cache invalidation strategies with TTL design
references/stampede-cdn-monitoring.md — cache stampede prevention techniques (mutex, probabilistic expiration, stale-while-revalidate) with Node.js code examples, Memcached use cases, CDN Cache-Control header configuration, and Redis monitoring and operations
Use this skill with your AI agent:Open on Skill Issue to copy, download, or add to your library.
Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.