gotchanextjsMajorpending
Next.js caching behavior — revalidation and cache busting
Viewed 0 times
revalidatePathrevalidateTagforce-dynamicno-storeISRrouter.refreshstale data
nodejsbrowser
Error Messages
Problem
Next.js App Router caches aggressively. Pages show stale data after mutations. fetch() results are cached indefinitely by default. Dynamic content appears static. Cache behavior changed between Next.js versions.
Solution
(1) fetch() caching: add { cache: 'no-store' } for always-fresh data, or { next: { revalidate: 60 } } for ISR (revalidate every 60s). (2) Route segment config: export const dynamic = 'force-dynamic' to opt out of caching for an entire route. (3) After mutations: call revalidatePath('/path') or revalidateTag('tag') in Server Actions. (4) Use tags for targeted revalidation: fetch(url, { next: { tags: ['posts'] } }) then revalidateTag('posts'). (5) Router cache: client-side cache of RSC payloads. Use router.refresh() to clear it. (6) Next.js 15 changed defaults: fetch is no longer cached by default. Check your version's docs.
Why
Next.js caches at multiple levels: fetch cache, full route cache, router cache, and data cache. Each has different invalidation mechanisms. Understanding which cache is serving stale data is key to fixing it.
Revisions (0)
No revisions yet.