Next.jsMedium
What is cache: 'no-store' used for in fetch?
cache: 'no-store' tells Next.js to fetch fresh data from the source on every request and never store the response in the Data Cache. It is how you opt a request out of caching in the previous caching model.
Behavior
- The request always goes to the network.
- In the previous model, using it makes the route dynamic: rendered per request instead of prerendered.
- Request memoization still applies within one render, so the same
no-storeURL is only called once per render.
Is it still needed?
- Next.js 15 and later:
fetchis not cached by default, sono-storemostly documents intent. It still matters when a route sets a caching default, for examplefetchCache = 'default-cache', or when you want to make dynamic rendering explicit. - Next.js 14 and earlier: essential, because
fetchdefaulted toforce-cache. - With Cache Components: a plain
fetchis already uncached request-time work; put the component behind<Suspense>. If you want to force request-time rendering for non-fetch work likeMath.random()orDate.now(), useawait connection()instead.
Typical uses
Live stock levels, account balances, prices that must be exact, and anything per-user from an external API.
Alternatives
next: { revalidate: 0 }has the same effect.export const dynamic = 'force-dynamic'made the whole route dynamic in the previous model; remove it when adopting Cache Components.
Code example
tsx
1// app/account/balance.tsx2import { cookies } from "next/headers";34export async function Balance() {5 const token = (await cookies()).get("token")?.value;67 // Always fresh: never cached, never shared between users8 const res = await fetch("https://bank.example.com/balance", {9 cache: "no-store",10 headers: { Authorization: `Bearer ${token}` },11 });12 const { amount } = await res.json();1314 return <p>Balance: ${amount}</p>;15}1617// app/account/page.tsx18// import { Suspense } from "react";19// export default function Page() {20// return (21// <Suspense fallback={<p>Loading balance…</p>}>22// <Balance />23// </Suspense>24// );25// }
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.