cache-components
Skill67 starsChanged 2 months agoMITView on GitHub
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.
6 other projects use a version of this.
Adopted by
Most recently taken up by
- jmolz/m0lz.01their own version, first seen May 19, 2026
- sangrokjung/claude-forgetheir own version, first seen May 3, 2026
- dbDev-code/w-skillstheir own version, first seen Mar 25, 2026
- Alpha-Park/openclaw-skillstheir own version, first seen Mar 22, 2026
- alphaparkinc/openclaw-skillstheir own version, first seen Mar 22, 2026
- mm-mazhar/agent-skills-configtheir own version, first seen Feb 10, 2026
Used with
Projects with it also use frontend-code-review, fullstack-developer and 4 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
DauQuangThanhSkillfrontend-code-review
Conducts comprehensive frontend code reviews including React/Vue/Angular component analysis, TypeScript/JavaScript quality assessment, CSS/styling review, performance optimization, accessibility compliance, security vulnerabilities, and best practices validation. Produces detailed review reports with specific issues, severity ratings, and actionable recommendations. Use when reviewing frontend code, analyzing React/Vue/Angular components, checking JavaScript/TypeScript quality, validating CSS/SCSS, assessing web performance, or when users mention "review frontend code", "check React components", "analyze JavaScript", "review TypeScript", "validate accessibility", or "frontend code quality".
Also in 4 projects that use this
belokonmSkillfullstack-developer
End-to-end feature expert specializing in frontend-backend integration, system architecture, and complete application development
Also in 3 projects that use this
GoogleSkillpr-creator
Also in 3 projects that use this
Hugging FaceSkillupdate-docs
Update documentation across the repo after API changes. Finds stale references in docs, examples, docstrings, and fixes them.
Also in 3 projects that use this
GoogleSkillcode-reviewer
Also in 3 projects that use this
VercelSkillfind-skills
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
Also in 4 projects that use this
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- sangrokjung/claude-forge★ 847same name
- alphaparkinc/openclaw-skills★ 9same name
- Alpha-Park/openclaw-skills★ 8same name
- dbDev-code/w-skills★ 1same name
- jmolz/m0lz.01★ 0same name
- mm-mazhar/agent-skills-config★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository30 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/ai-sdk-6/references/agents.mdAGENTS.md
- skills/ai-sdk-7/references/agents.mdAGENTS.md
- skills/openai-agents-sdk/references/agents.mdAGENTS.md
- skills/react-best-practices/AGENTS.mdAGENTS.md
- skills/vercel-react-view-transitions/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- ai-appSkill
- ai-elementsSkill
- ai-sdk-6Skill
- ai-sdk-7Skill
- ai-sdkSkill
- chrome-devtoolsSkill
- frontend-designSkill
- goSkill
- handoffSkill
- hetzner-cloudSkill
- iconsSkill
- next-best-practicesSkill
- nextjs-chatbotSkill
- nextjs-seoSkill
- nextjs-shadcnSkill
- openai-agents-sdkSkill
- postgres-semantic-searchSkill
- react-best-practicesSkill
- shadcnSkill
- skill-creatorSkill
- supabase-postgres-best-practicesSkill
- vercel-react-view-transitionsSkill
- web-design-guidelinesSkill
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 3 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Keep the project's caching mode unless migration is requested.
- Very specific: line 14
Read the relevant guide in node_modules/next/dist/docs/ first (bundled since 16.2.
- Distinctive: line 119
Keep uncached I/O and request-only content below appropriate Suspense boundaries.
- Distinctive: line 131
Use tags when invalidation must reach the same entity across routes, path invalidation for route-specific output, or expiry where that …
- Very specific: line 150
Run the production build, then exercise cold/direct navigation, client navigation, the relevant mutation and subsequent read under next …
- Distinctive: line 152
Check tenant isolation and multi-instance invalidation when applicable.
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Cache Components
Keep the project's caching mode unless migration is requested. Confirm the
installed Next.js version and cacheComponents configuration before applying
these patterns.
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.
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 replacesexperimental.dynamicIO,experimental.useCacheandexperimental.ppr;cacheLife/cacheTagimport fromnext/cachewithoutunstable_. - With it enabled, segment exports
dynamic,revalidate,fetchCacheanddynamicParamsare errors, and Edge runtime is unsupported.revalidate = NbecomescacheLife(nearest or custom profile) insideuse cache;force-dynamicandfetchCacheare unnecessary; fetchnext: { revalidate, tags }becomescacheLife/cacheTagin ause cachefunction; request data goes under Suspense;dynamicParams = falsebecomesnotFound()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 cacheis 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 onlysecondsdoes. 16.3 addsstalethresholds (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 inuse cache, or defer withawait io()(next/cache, 16.3+) orawait 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) asks dev/build to validate instant navigation into a segment.instant = falsepermits a blocking route; it does not clear synchronous-IO errors.
For whole-app adoption or instant-navigation work, Next.js publishes workflow
skills (next-cache-components-adoption, next-cache-components-optimizer)
in vercel/next.js/skills; the bundled migration guide covers 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.
import { Suspense } from 'react'
import { cookies } from 'next/headers'
import { cacheLife, cacheTag, updateTag } from 'next/cache'
import { insertPost, listPosts } from '@/lib/posts' // project code
import { requireEditor } from '@/lib/auth' // throws unless the session may edit
async function getPosts() {
'use cache' // shared entry: no cookies/headers/searchParams inside
cacheLife('hours')
cacheTag('posts')
return listPosts()
}
async function Theme() {
const theme = (await cookies()).get('theme')?.value // request-time, outside the cache
return <p>Theme: {theme ?? 'system'}</p>
}
async function addPost(formData: FormData) {
'use server'
await requireEditor()
const title = String(formData.get('title') ?? '').trim()
if (!title) return
await insertPost(title)
updateTag('posts') // Server Actions only; the next read waits for fresh data
}
export default async function Page() {
const posts = await getPosts() // cached, so it can be part of the static shell
return (
<>
<ul>{posts.map((p) => <li key={p.id}>{p.title}</li>)}</ul>
<Suspense fallback={<p>Theme: …</p>}><Theme /></Suspense>
<form action={addPost}><input name="title" /><button>Add</button></form>
</>
)
}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 callconnection(), 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, thenext-request-in-use-cacheerror can passnext buildand surface only undernext 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.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

