caching-strategy-advisor
Recommends the right caching layer, TTL strategy, and invalidation approach for any application bottleneck.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Recommends the right caching layer, TTL strategy, and invalidation approach for any application bottleneck.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Runs a systematic checklist review on any code diff or file, covering correctness, security, performance, and readability.
Writes a high-quality CLAUDE.md, .cursorrules, or .windsurfrules file that gives a coding agent the right project context, conventions, and constraints to work effectively.
Designs an eval suite for an LLM agent or pipeline including success metrics, trajectory scoring, LLM-as-judge setup, and regression test cases.
Designs a hybrid retrieval pipeline combining dense vector search and BM25 sparse search with reciprocal rank fusion, and explains when to use each configuration.
Converts a workflow description into a LangGraph node/edge graph with typed state, conditional routing, and human-in-the-loop checkpoints.
Audits an AI application for unnecessary token spend and recommends prompt caching, model routing, and token reduction techniques to cut costs.
| name | Caching Strategy Advisor |
| description | Recommends the right caching layer, TTL strategy, and invalidation approach for any application bottleneck. |
| category | devops |
| tags | ["caching","performance","redis","cdn","backend"] |
| author | simplyutils |
This skill analyzes a performance bottleneck, a slow query, or an expensive operation and recommends the right caching strategy for it — which cache layer to use, what TTL to set, how to handle cache invalidation, and what to watch out for. It covers in-memory caches, Redis, HTTP caching headers, CDN caching, and database query caching, and explains the trade-offs of each recommendation.
Use this when you have a slow API, a database that's under heavy read load, a page that's slow to load, or any operation that's expensive and called frequently.
Copy this file to .agents/skills/caching-strategy-advisor/SKILL.md in your project root.
Then ask:
Provide:
Add the instructions below to your .cursorrules or paste them into the Cursor AI pane with the context above.
Provide the operation description and context. Ask Codex to follow the instructions below to produce the caching recommendation.
When asked to advise on a caching strategy, follow these steps:
Ask or infer:
Choose the appropriate layer(s):
In-process / in-memory cache (e.g., a Map or LRU cache in the application itself)
Redis / Memcached (distributed key-value cache)
HTTP response caching (Cache-Control headers)
ETag or Last-Modified for conditional requests.CDN caching (Cloudflare, CloudFront, Fastly)
Database query cache / materialized views
TTL (Time-to-live)
Invalidation strategies:
Always check for:
## Caching Strategy Recommendation
### Problem Summary
[1–2 sentences describing the bottleneck and the key workload characteristics]
### Recommended Strategy
[Which cache layer(s) to use and why]
### Implementation Plan
#### Cache Layer: [Layer name]
- **What to cache**: [The exact query result, API response, computed value]
- **Cache key structure**: `[prefix]:[identifier]` (e.g., `product:list:category:electronics:page:1`)
- **TTL**: [Value and reasoning]
- **Invalidation**: [How and when to invalidate]
- **Storage estimate**: [Approximate size per entry × expected number of entries]
### Code Pattern
[Pseudocode or real code example showing the cache-aside or write-through pattern]
### Risks and Mitigations
| Risk | Mitigation |
|------|-----------|
| [Risk] | [How to address it] |
### Expected Impact
[Estimated reduction in DB load, latency improvement, or throughput increase]
### What NOT to cache
[Any related data that should NOT be cached, and why]
Input to Agent:
"Use the Caching Strategy Advisor skill. Our
GET /api/productsendpoint queries the database for a product catalog (500 products, with category and price info). It's called 2,000 times per minute. Products are updated by staff roughly once per hour. Our stack is Node.js + PostgreSQL + Redis (already available). Stale data for up to 5 minutes is acceptable."
Output from Agent:
Caching Strategy Recommendation
Problem Summary
The product catalog is read-heavy (2,000 req/min), changes infrequently (~hourly), and can tolerate up to 5 minutes of staleness. This is an ideal candidate for a Redis cache with a TTL-based expiry.
Recommended Strategy
Cache the query result in Redis with a 5-minute TTL. Use a cache-aside pattern: on a cache miss, query PostgreSQL and populate the cache. No event-based invalidation needed given the acceptable staleness window.
Implementation Plan
Cache Layer: Redis
- What to cache: Full serialized response of
GET /api/products(the array of 500 products with category and price)- Cache key:
products:catalog:all(if no filtering);products:catalog:category:[slug](if filtered by category)- TTL: 5 minutes (300 seconds)
- Invalidation: TTL-only. Optionally: explicitly delete the key after a staff product update for immediate freshness.
- Storage estimate: ~500 products × ~500 bytes = ~250KB per cache key — well within Redis limits
Code Pattern
async function getProducts(category?: string): Promise<Product[]> { const cacheKey = category ? `products:catalog:category:${category}` : 'products:catalog:all'; const cached = await redis.get(cacheKey); if (cached) return JSON.parse(cached); const products = await db.query('SELECT * FROM products WHERE ...', [category]); await redis.setex(cacheKey, 300, JSON.stringify(products)); // TTL: 300s return products; }Risks and Mitigations
Risk Mitigation Cache stampede (all cache keys expire at once) Add small random jitter to TTL: 300 + Math.floor(Math.random() * 30)Cold start on deploy Pre-warm cache on server startup by calling getProducts()Expected Impact
DB read load for this endpoint drops by ~98% (cache miss rate will be very low at 2,000 req/min with 5-minute TTL).