laguagu/claude-code-nextjs-skills/cache-components
- community
- ext:[{"type":"config","description":"Configuration overrides"}]
Checking that the SKILL.md file is still in the repository.
Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). Use when implementing 'use cache' directive, configuring cache lifetimes with cacheLife(), tagging cached data with cacheTag(), invalidating caches with updateTag()/revalidateTag(), optimizing static vs dynamic content boundaries, instant navigation validation, 'use cache: private', pass-through/interleaving patterns, GET Route Handler caching, debugging cache issues, and reviewing Cache Component implementations.
Install
npx vskill@latest install laguagu/claude-code-nextjs-skills/cache-componentsSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
Cache Components
Keep the project's caching mode unless migration is requested. Confirm the installed Next.js version and cacheComponents/partialPrefetching configuration before applying these patterns. Use Cache Components on next 16.4.1+: 16.0.0–16.4.0 allow unauthenticated RCE through use cache functions returning typed arrays (GHSA-673q-mjm6-r5xr; no workaround, upgrade even without such functions). Flag an affected install before cache work.
Read the relevant guide in node_modules/next/dist/docs/ first (bundled since 16.2; in a monorepo, use the app's own next package). Web paths map to files with numbered folders, so find them by name: .../functions/cacheLife is 01-app/03-api-reference/04-functions/cacheLife.md. Under 01-app/, start with 02-guides/migrating-to-cache-components.md, 01-getting-started/08-caching.md and 02-guides/instant-navigation.md. Error pages under /docs/messages are not bundled; next dev/next build print the fix options inline. Without local docs, use the official caching docs. Exact exports and signatures are also in node_modules/next/cache.d.ts. For static-output and staged-deferral questions in 16.4+, find the installed ensureStatic route-segment reference and navigation/prefetch function references by name.
The goal is a useful prerendered shell with freshness and authorization rules that remain correct after mutations, deploys and client navigation.
Facts older examples get wrong
- Next.js 16 enables the mode with top-level
cacheComponents: true. It replaces
experimental.dynamicIO, experimental.useCache and experimental.ppr; cacheLife/cacheTag import from next/cache without unstable_. In 16.4, set partialPrefetching explicitly: leaving it unset warns; recommended create-next-app defaults enable both flags.
- With it enabled, segment exports
dynamic,revalidate,fetchCache,
dynamicParams and runtime (even 'nodejs') are errors; only the default Node.js runtime is supported. revalidate = N becomes cacheLife (nearest or custom profile) inside use cache; force-dynamic and fetchCache are unnecessary; fetch next: { revalidate, tags } becomes cacheLife/cacheTag in a use cache function; request data goes under Suspense; dynamicParams = false becomes notFound() for unknown params.
- Existing
fetchandunstable_cachecaching still works as a separate layer,
so do not mechanically rewrite every read. Its persistence across deployments and instances depends on retained/shared storage; self-hosted instances do not share it by default. use cache is in-memory by default; even a durable handler cannot reuse entries when the build/deployment ID changes.
generateStaticParamsmust return at least one param:[]fails the build,
and removing the export renders the route on every request.
revalidate: 0orexpireunder 5 minutes makes a request-time hole instead
of prerendered output; of the presets only seconds does. 16.3 adds stale thresholds (under 30 s: not prerendered; under 5 min: not in the App Shell).
- Synchronous
new Date(),Math.random()orcrypto.randomUUID()during
prerender is an error: capture it in use cache, or defer with await io() (next/cache, 16.3+) or await connection() (next/server) under Suspense.
use cache: privatewas experimental through 16.2. It runs at request time,
stays out of the static shell and accepts no custom handler.
export const instant(16.3;unstable_instantin 16.2) opts a segment into
instant-navigation validation. Since 16.3, every Page/Default segment is implicitly validated in next dev only (dev overlay) at the default level; build validation requires experimental.instantInsights.validationLevel set to experimental-error or experimental-manual-error (16.2 unstable_instant also validated at build). Test navigations with @next/playwright instant(). instant = false permits a blocking route; it does not clear synchronous-IO errors.
For whole-app adoption of Cache Components or Partial Prefetching, use the official workflow skills listed in the installed 01-app/02-guides/ai-agents.md (from vercel/next.js skills/); the bundled 02-guides/migrating-to-cache-components.md and adopting-partial-prefetching.md cover the same steps.
Shape of one route
app/posts/page.tsx, checked against next 16.3.8 with cacheComponents: true (tsc --noEmit, next build, the action under next start). @/lib/* is project code.
Decide the boundary
- Cache reusable results when the product's freshness and data policy permit.
Static content needs no directive just to be static.
- A plain
use cachescope cannot read cookies, headers, searchParams or call
connection(), including indirectly through helpers. Read those outside and pass authorized, serializable values. Account/tenant IDs must participate in the cache key when output depends on them. On a dynamically rendered route, the next-request-in-use-cache error can pass next build and surface only under next start.
- Keep uncached I/O and request-only content below appropriate Suspense
boundaries. Suspense supplies fallback UI; it does not itself make synchronous work dynamic.
- Evaluate private/remote variants against installed docs and deployment
handlers. Private caching is not a compliance guarantee; remote caching is not a consistency protocol.
Define freshness and invalidation
Choose lifetimes from actual acceptable staleness. Named profiles can be overridden by the project; read its config before assuming a duration.
Use tags when invalidation must reach the same entity across routes, path invalidation for route-specific output, or expiry where that meets the contract. Authenticate, authorize and validate before mutations. Invalidate only affected cached data:
updateTag: immediate expiry/read-your-writes, Server Actions only.revalidateTag(tag, 'max'): stale-while-revalidate on a later visit.revalidateTag(tag, { expire: 0 }): immediate expiry where a webhook/Route
Handler needs it. The one-argument form is deprecated.
These tag APIs can also apply to tagged fetch data; their availability does not by itself mean Cache Components is enabled.
Read for the problem
- API boundaries: keys, serialization, lifetimes, handlers and route APIs.
- Composition: tenant isolation, nested caches, pass-through and dynamic params.
- Troubleshooting: diagnose blocking, stale or inconsistent output.
Run the production build, then exercise cold/direct navigation, client navigation, the relevant mutation and subsequent read under next start. Check tenant isolation and multi-instance invalidation when applicable. A passing build cannot establish those behaviors.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cache-components/SKILL.md
Popularity
- Repository stars
- 12
- Repository forks
- 4
- 7-day trend score
- 13
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 22 Mar 2026, 7 months ago.
Extension points
configConfiguration overrides
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/laguagu/claude-code-nextjs-skills/cache-components)