Explicit fetch cache options
What you need to know
A server-side fetch in Next.js can reuse an earlier response or deliberately read the origin again. Choose the policy for each piece of data: public book descriptions may tolerate reuse, but a reader’s private checkout status should be obtained for the current authorized request.
By the end, you can: choose no-store or force-cache; predict origin read expectations.
Opt into public data caching
// Partial server helper; the local origin is provided by the V6 lab.export async function readPublicCatalog() { const response = await fetch('http://127.0.0.1:4317/catalog', { cache: 'force-cache', next: { tags: ['catalog'] } }); if (!response.ok) throw new Error('Catalog unavailable'); return response.json(); // validate before rendering real external data}Expected behavior (not framework-tested): An eligible warm cache entry may avoid a new origin request. The tag is an invalidation label, not a URL.
How it works
In the App Router with Cache Components disabled, cache: 'force-cache' opts into the persistent server Data Cache, while cache: 'no-store' opts out. These are framework-side semantics, not the browser HTTP cache settings. Without an explicit option, the behavior also depends on whether the route is prerendered or request-time; do not infer persistent caching from an omitted option. The same URL is not the whole cache key: method, headers and body can matter. A successful response must still be checked and decoded before use.
Keep five different reuse mechanisms in mind: render-request memoization can avoid repeated equivalent GET reads in a React render; the Data Cache can persist fetched data between requests; the Full Route Cache stores eligible rendered route output; the Router Cache holds navigation payloads in the browser; and browser/CDN HTTP caches follow their own policy. A dynamic route can use a cached public read alongside an uncached request-specific read. A cache miss is not an error, and an origin counter does not alone identify which cache was used.
Read live public availability
// Partial server helper, same lab origin.export async function readLiveAvailability() { const response = await fetch('http://127.0.0.1:4317/availability', { cache: 'no-store' }); if (!response.ok) throw new Error('Availability unavailable'); return response.json();}Expected behavior (not framework-tested): A new request-time render can obtain current availability. Repeated reads within one render may still be memoized; client navigation may not initiate a new server render.
Common mistake
Combining cache: "no-store" with a positive next.revalidate asks for contradictory behavior. Choose one coherent policy rather than depending on framework conflict handling. Do not put user-specific responses in a shared persistent cache merely because the fetch accepts credentials.
Practice and verification
Classify a public title, anonymous stock number and authenticated reading history. For each, state the freshness requirement and whether sharing is safe. Predict the origin counter for two separate server renders, then explain why a browser back navigation is a different test.
Scope: App Router, proposed Next.js 16.x, Cache Components disabled for these labs. Snippets assume a reviewed TypeScript app and are static examples; framework behavior has not been executed. Exact supported patch and dependency set must be verified before running.
Further reading: Fetch · Cache Model