Goal: cache the right data at the right granularity and invalidate cleanly.
Use for:
- choosing a caching strategy per route or data source
- stale or over-cached pages after deploys
- mixing static and dynamic content on one route
Workflow:
- Classify each data source: static, revalidated, or dynamic.
- Wrap cacheable work with the use cache directive.
- Set freshness with cacheLife profiles per data type.
- Tag cached entries with cacheTag for targeted invalidation.
- Invalidate with revalidateTag/revalidatePath on writes.
- Use Partial Prerendering to serve a static shell with dynamic holes.
Decisions:
- static content: cache aggressively, long cacheLife
- frequently changing: short cacheLife or tag-based revalidation
- per-request/user data: keep dynamic, do not cache
- mixed pages: PPR with Suspense boundaries
Rules:
- tag anything you may need to invalidate later
- revalidate by tag on the mutation that changes the data
- never cache user-specific or secret-bearing responses
- verify freshness after deploy, not just locally