From ultrapowers-dev
Use when adding caching to a system, choosing cache strategies, designing invalidation logic, or diagnosing cache-related bugs.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ultrapowers-dev:cachingThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Cache the right thing at the right layer with the right TTL. The two hardest problems in caching are invalidation and knowing when not to cache at all.
Cache the right thing at the right layer with the right TTL. The two hardest problems in caching are invalidation and knowing when not to cache at all.
| Strategy | How It Works | Best For |
|---|---|---|
| Cache-Aside | App checks cache, on miss reads source and populates | General purpose, most common |
| Read-Through | Cache fetches from source on miss | Cache layer manages population |
| Write-Through | Writes go to cache and source synchronously | Strong consistency |
| Write-Behind | Writes to cache, async flush to source | High write throughput |
Default: cache-aside. Simple, explicit, you control both paths.
read(key):
value = cache.get(key)
if miss: value = db.get(key); cache.set(key, value, ttl)
return value
write(key, value):
db.set(key, value)
cache.delete(key) // Delete, don't update
Delete on write, don't update -- updating risks race conditions where a stale write overwrites a newer one.
| Strategy | Trade-off |
|---|---|
| TTL-based | Simple but serves stale data until expiry |
| Event-based | Consistent but requires event infrastructure |
| Version-based | Good for static assets, manual management |
| Purge on deploy | Safe for config/template caches |
| Data Type | Suggested TTL |
|---|---|
| User session | 15-30 minutes |
| External API response | 60-300 seconds |
| Config / feature flags | 30-60 seconds |
| Static assets | Hours to days (version URLs handle invalidation) |
| Scenario | Why |
|---|---|
| Write-heavy, read-once data | Cache churn with no read benefit |
| Highly personalized data | Low hit rate, memory wasted |
| Must be real-time consistent | Stale cache causes correctness bugs |
| Cache same speed as source | Complexity without performance gain |
| Technique | How It Works |
|---|---|
| Lock on cache miss | One request populates, others wait |
| Stale-while-revalidate | Serve expired value, refresh in background |
| Request coalescing | Deduplicate concurrent requests for same key |
| Mistake | Fix |
|---|---|
| No TTL set | Always set a TTL -- prevents infinite stale data |
| Updating cache on write instead of deleting | Delete on write; next read repopulates |
| Caching errors or empty results | Cache only successful responses |
| No hit/miss monitoring | Track hit rate -- below 80% means cache isn't helping |
| Ignoring cold-start behavior | Plan warm-up or stale-while-revalidate |
Original -- Datatide, MIT licensed.
npx claudepluginhub ennio-datatide/ultrapowers-devDesign multi-layer caching strategies (client, edge, service, database) for performance. Use when optimizing latency or reducing database load.
Analyzes cache strategies, invalidates patterns, and detects issues in Redis, Memcached, or in-memory caches. Guides TTL assessment, access pattern analysis, and anti-pattern detection.
Provides caching strategies (Cache-Aside, Read-Through, Write-Through, Write-Behind), invalidation approaches, multi-level caching, and Redis data structures for audits and generation.