{"success":true,"name":"learn-the-next-js-caching-layers-before-fighting-them","description":"Next.js shows old data and cache behavior feels random","category":"ai-brimind","path":"ai-brimind/learn-the-next-js-caching-layers-before-fighting-them/SKILL.md","file":"SKILL.md","content":"---\nname: learn-the-next-js-caching-layers-before-fighting-them\ndescription: \"Next.js shows old data and cache behavior feels random\"\n---\n\n# Learn the Next.js Caching Layers Before Fighting Them\n\n## When to use\nProject is Next.js App Router, and data looks stale or 'too fresh', and you are about to sprinkle no-store or force-dynamic everywhere.\n\n## Example request\nadding cache: 'no-store' to every fetch to make data fresh → all speed from caching is thrown away to fix one route. — Shotgun disabling. | page updates on the server but the browser still shows old content when navigating back → that is the client-side Router Cache, a different layer than the data cache. — Wrong layer diagnosed. | one fetch result should live 60 seconds, another must be per-request → each fetch can set its own revalidate; caching is per-call, not global. — Per-fetch control. | data changed after a form submit but pages still show old values → the fix is revalidatePath or revalidateTag after the mutation, not disabling cache. — Invalidate, don't disable.\n\n## Instructions\nAct like an engineer who refuses to touch cache settings before naming which cache is involved. When Next.js data seems stale or inconsistent: 1) Name the layers out loud: the Data Cache (fetch results on the server), the Full Route Cache (prerendered pages), and the Router Cache (client-side, in the browser during navigation). Each has different rules and different fixes. 2) Reproduce the problem and classify it: stale after a mutation → you forgot to invalidate (revalidatePath / revalidateTag); stale on client back/forward navigation → Router Cache behavior; page never updates at all → the route is static and needs a revalidate interval or a rebuild. 3) Choose the narrowest fix: set revalidate on the specific fetch or route that needs it, or invalidate the specific path/tag after the write. Global force-dynamic or no-store everywhere is a last resort that must be justified in one sentence, because it deletes performance for the whole app. 4) Prefer the built-in mechanisms (revalidate, tags, revalidatePath) over custom timestamp query params or hand-rolled cache-busting tricks. 5) If you cannot say which layer serves the stale content, test it: hard refresh vs client navigation vs new incognito window tell the layers apart. Only change settings once the layer is confirmed, and explain why this exact layer produced the staleness — not just that the data finally looks fresh.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #497\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}