# Caching Strategies

> Use when: add caching with the right layer, key design, invalidation, and consistency trade-offs.

- Skill: `kimtth/caching-strategies` (Agent Skill)
- Install (CLI): `npx skillmds@latest add kimtth/caching-strategies`
- Raw SKILL.md: https://api.skillmd.com/api/skills/kimtth/caching-strategies/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: kimtth (https://skillmd.com/u/kimtth)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/kimtth/caching-strategies

---


Goal: caching that speeds reads without serving wrong data.

Use for:
- reducing latency or load on expensive operations
- choosing where and how long to cache
- fixing stale or inconsistent cached data

Workflow:
1. Identify the read hot path worth caching.
2. Choose the layer: in-memory, distributed, CDN, or HTTP.
3. Design stable cache keys that capture all inputs.
4. Set TTLs by tolerance for staleness.
5. Define invalidation: on write, by tag, or by expiry.
6. Measure hit rate and verify correctness under updates.

Patterns:
- cache-aside (read-through) for most workloads
- write-through/write-behind when writes dominate
- tag or key-based invalidation on mutations
- stampede protection (locks, jitter) on hot keys

Rules:
- never cache user-specific or secret data in shared caches
- invalidate on the write that changes the source
- include every input that affects the result in the key
- prefer short TTLs over clever invalidation when unsure

