How Will This fetch Be Cached?
Medium · Caching
In Server Components, Next.js extends fetch with caching options:
- cache: "force-cache": store the response in the Data Cache and reuse it.
- next: { revalidate: n }: reuse it for up to n seconds, then refresh it (time-based revalidation). revalidate: false means cache forever.
- cache: "no-store" / "no-cache" or revalidate: 0: fetch on every request (dynamic).
- **No options**: since Next.js 15, fetch is **not cached** by default, so here it counts as "dynamic". (The route itself can still be pre-rendered once at build time if nothing else on it is dynamic.)
Some combinations contradict each other. Next.js then prints a warning and **ignores both** options (so the fetch behaves as if you passed neither):
- cache: "no-store" with revalidate greater than 0 or false.
- cache: "force-cache" with revalidate: 0.
The warning text is Specified "cache: <cache>" and "revalidate: <revalidate>", only one should be specified.
Write fetchCacheMode(options?) that returns { mode, warning }:
- mode is "dynamic", "cached" or "revalidate:<n>".
- Check in this order: no-store / no-cache or revalidate: 0 gives "dynamic"; a positive revalidate gives "revalidate:<n>" (even together with force-cache); revalidate: false or force-cache gives "cached"; otherwise "dynamic". (cache: "default" counts as no option.)
- warning is the text above for a conflict, otherwise null.
(Simplified: the real logic also looks at segment config such as fetchCache, request headers and the HTTP method.)