Skip to the solution
MediumFrontend4 min read

How does fetch caching work in the Next.js App Router (force-cache, no-store, revalidate)?

909 views

The problem

Question presented to candidate: "Walk me through the options you can pass to fetch in a Server Component and what each does to caching and to the route. What is the default today?"

What a strong answer should cover:

  • By default a fetch result is not stored across requests (since Next.js 15), but a fetch reached during a static render runs at build time and its result is baked into the page.
  • cache: 'force-cache' stores the result in the Data Cache and reuses it across requests, even in a dynamic route.
  • cache: 'no-store' fetches on every request and makes the route dynamic.
  • next: { revalidate: n } stores the result for n seconds, then serves the stale value while refetching in the background.
  • next: { tags: [...] } labels the entry so revalidateTag can clear it on demand; these options belong to the previous model, while Cache Components uses 'use cache'.

Clarifying questions expected:

  • "How fresh does this data have to be?" β€” seconds, minutes, or exact.
  • "Is Cache Components on?" β€” then fetch options give way to 'use cache' and cacheLife.

Code / implementation expected: Yes β€” the four fetch styles and what the build makes of them.

  • nextjs
  • fetch
  • caching
  • revalidate

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

4 min read Β· 8 sections

Read the code

The fetch styles in one file
const API = "https://api.example.com";

export default async function Page() {
  const settings = await fetch(`${API}/settings`, { cache: "force-cache" });  // stored until revalidated
  const headlines = await fetch(`${API}/news`, { next: { revalidate: 60 } });  // refreshed after 60 s
  const posts = await fetch(`${API}/posts`, { next: { tags: ["posts"] } });     // clearable with revalidateTag
  const stock = await fetch(`${API}/stock`, { cache: "no-store" });             // every request, route is dynamic
  // ...
  return null;
}

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 40 of 129 in Next.js

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All Next.js questions
Up nextMedium

How do you fetch data in Next.js Client Components (SWR, React Query, use)?

Continue