In Next.js 14 my fetch calls were cached by default and I had to opt out. After upgrading to 15 behaviour seems different. What is cached by default now and how do I control it?
DEV3 Developer Forum
Why is my fetch data stale in Next.js 15 and how does caching work now?
Ask a question
Every post is reviewed first. Usually reviewed within 24 hours.
dev3 ·
0
1 reply
dev3 · Accepted answer
Next.js 15 changed the defaults: fetch requests and GET route handlers are no longer cached by default. Next 14 defaulted to force-cache.
Controlling a single fetch
// cache indefinitely until revalidated
await fetch(url, { cache: "force-cache" });
// revalidate at most every 60 seconds
await fetch(url, { next: { revalidate: 60 } });
// tag it so you can invalidate on demand
await fetch(url, { next: { tags: ["products"] } });
Whole route segment
export const revalidate = 3600; // ISR style
export const dynamic = "force-static"; // or "force-dynamic"
On-demand invalidation
"use server";
import { revalidateTag, revalidatePath } from "next/cache";
export async function saveProduct() {
// ...write to DB
revalidateTag("products");
revalidatePath("/products");
}
Non-fetch data (ORM, Mongo)
fetch options do not apply to direct database calls. Wrap them with unstable_cache (or the newer use cache directive where enabled in your version) and give tags:
import { unstable_cache } from "next/cache";
export const getProducts = unstable_cache(
async () => db.product.findMany(),
["products"],
{ tags: ["products"], revalidate: 300 }
);
Layers to remember
- Request memoisation (same fetch in one render is deduped).
- Data cache (server, persists across requests).
- Full route cache (static HTML/RSC payload).
- Router cache (client side; in Next 15 page segments default to staleTime 0).
Pitfall: using cookies(), headers() or searchParams makes the route dynamic, so route-level caching will not apply. In Next 15 those APIs are async and must be awaited. Check the Next.js caching docs for your exact minor version as the use cache APIs are evolving.
0