trinhhaox/ag-kit/caching-strategies
Claude Code and agent skill by trinhhaox/ag-kit
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Multi-layer caching patterns - Browser, CDN, Redis, app-level, DB cache. Invalidation strategies, ISR, SWR, thundering herd prevention.
Install
npx vskill@latest install trinhhaox/ag-kit/caching-strategiesSKILL.md
Caching Strategies
End-to-end caching patterns from browser to database.
5-Tier Caching Pyramid
Primary Strategies
Cache-Aside (Lazy Loading)
Use when: Read-heavy, tolerance for occasional stale data.
Write-Through
Use when: Consistency matters, write frequency is moderate.
Write-Behind (Write-Back)
- Write to cache immediately, async flush to DB
- Risk: Data loss if cache crashes before flush
- Use when: High write throughput, eventual consistency OK
Read-Through
- Cache fetches from DB automatically on miss
- Simpler code, cache library handles population
Stale-While-Revalidate (SWR)
HTTP Cache Headers
| Directive | Purpose | |
|---|---|---|
Cache-Control: public, max-age=31536000 | Static assets (immutable) | |
Cache-Control: private, no-cache | Per-user data, always revalidate | |
Cache-Control: s-maxage=3600, stale-while-revalidate=86400 | CDN cache with SWR | |
ETag: "abc123" | Conditional requests (304 Not Modified) | |
Vary: Accept-Encoding, Authorization | Cache variants |
Redis Patterns
Key Naming Convention
TTL Guidelines
| Data Type | TTL | Reason | |
|---|---|---|---|
| User sessions | 30min-24h | Security | |
| API responses | 5min-1h | Freshness | |
| Static config | 24h-7d | Rarely changes | |
| Computed results | 1h-24h | Cost of recompute |
Invalidation Patterns
Event-Driven:
Tag-Based:
Versioned Keys:
Next.js Specific
ISR (Incremental Static Regeneration)
fetch() Caching
Common Pitfalls
| Pitfall | Solution | |
|---|---|---|
| Cache stampede | Mutex/lock on cache miss, only one request populates | |
| Thundering herd | Stagger TTLs with jitter: TTL + random(0, TTL*0.1) | |
| Dogpiling | Background refresh before expiry | |
| Key explosion | Limit key cardinality, use hash structures | |
| Stale data | Event-driven invalidation, short TTLs for mutable data | |
| Cold start | Cache warming on deploy |
Monitoring Targets
- Hit rate > 90%
- P99 latency < 5ms (Redis)
- Eviction rate stable (not climbing)
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/caching-strategies/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/trinhhaox/ag-kit/caching-strategies)