# API Cache Invalidation Strategies

> Design API cache invalidation: TTL, ETag revalidation, stale-while-revalidate, Surrogate-Key purge, and hybrid strategies. Use when cached data goes stale or planning purge workflows.

- Skill: `deangrant/api-cache-invalidation-strategies` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx skillmds@latest add deangrant/api-cache-invalidation-strategies`
- Raw SKILL.md: https://api.skillmd.com/api/skills/deangrant/api-cache-invalidation-strategies/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: deangrant (https://skillmd.com/u/deangrant)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/deangrant/api-cache-invalidation-strategies

---


# Cache Invalidation Strategies

Use this skill when deciding **how cached API responses become fresh**.

---

## 1. Strategies

| Strategy | Idea |
| -------- | ---- |
| TTL / max-age | Time-based expiry |
| ETag / 304 | Revalidate cheaply |
| stale-while-revalidate | Serve stale while refreshing |
| Surrogate-Key / tag purge | Explicit CDN/edge purge by key |
| Hybrid | Short TTL + event-driven purge |

---

## 2. Guidance

- Prefer event-driven purge for correctness-critical data; TTL for soft freshness.
- Include auth/tenant in cache keys.
- Avoid thundering herds: SWR, soft locks, or randomized expiry.

---

## 3. Quick checklist

- [ ] Freshness requirements classified (soft vs hard).
- [ ] Key design includes tenant/user where needed.
- [ ] Purge path tested for tagged content.
- [ ] Stampede mitigations for popular keys.

See [reference.md](reference.md) and [examples.md](examples.md).

