Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
Use when you need the cache refreshed within the same request:
'use server'import { updateTag } from'next/cache'exportasyncfunctionupdateProduct(id: string, data: FormData) {
await db.products.update({ where: { id }, data })
updateTag(`product-${id}`) // Immediate - same request sees fresh data
}
revalidateTag() - Background Revalidation
Use for stale-while-revalidate behavior:
'use server'import { revalidateTag } from'next/cache'exportasyncfunctioncreatePost(data: FormData) {
await db.posts.create({ data })
revalidateTag('posts', 'max') // Background SWR — single-arg form is deprecated in Next 16// immediate webhook-style expiry: revalidateTag('posts', { expire: 0 })
}
refresh() - Refresh Uncached Data
Third member of the triad: refreshes DYNAMIC (uncached) data from a Server
Action w/o touching caches — e.g. after a mutation that only affects
per-request data:
Nested-cache gotcha: an outer use cache w/o explicit cacheLife inherits
the SHORTEST inner lifetime; short-lived caches (expire < 5m) become
dynamic holes & error during prerender unless given an explicit profile.
Runtime Data Constraint
Cannot access cookies(), headers(), or searchParams inside use cache.
Solution: Pass as Arguments
// Wrong - runtime API inside use cacheasyncfunctionCachedProfile() {
'use cache'const session = (awaitcookies()).get('session')?.value// Error!return<div>{session}</div>
}
// Correct - extract outside, pass as argumentasyncfunctionProfilePage() {
const session = (awaitcookies()).get('session')?.valuereturn<CachedProfilesessionId={session} />
}
asyncfunctionCachedProfile({ sessionId }: { sessionId: string }) {
'use cache'// sessionId becomes part of cache key automaticallyconst data = awaitfetchUserData(sessionId)
return<div>{data.name}</div>
}
Exception: use cache: private
For compliance requirements when you can't refactor:
Non-deterministic values (Math.random(), Date.now()) execute once at build time inside use cache
For request-time randomness outside cache:
import { connection } from'next/server'asyncfunctionDynamicContent() {
awaitconnection() // Defer to request timeconst id = crypto.randomUUID() // Different per requestreturn<div>{id}</div>
}