Data Fetching and Caching Questions
How is fetch caching different in Next.js 15 compared with 14?
In 14, fetch in Server Components was cached by default (force-cache). In 15+ it is not cached by default; you opt in with cache: 'force-cache' or next: { revalidate: N, tags: [...] }. GET Route Handlers and the client router cache for pages also became uncached by default.
await fetch(url, { next: { revalidate: 60, tags: ['products'] } });What is the difference between revalidatePath and revalidateTag?
revalidatePath('/products/42') invalidates the cached output of a route. revalidateTag('product-42') invalidates every cached fetch / 'use cache' entry labelled with that tag, wherever it is used. Tags are more precise for entities that appear on many pages. In Next.js 16, revalidateTag(tag, profile) takes a cacheLife profile and updateTag expires a tag immediately inside Server Actions.
What does React cache() do and how is it different from the Data Cache?
cache(fn) memoises a function for one server request, so the layout, page and generateMetadata can all call getProduct(42) and hit the database once. The Data Cache (fetch cache / 'use cache') persists across requests and users until revalidated.
What is the 'use cache' directive?
Part of Cache Components (Next.js 16, cacheComponents: true). Marking a function, component or file with 'use cache' caches its return value, keyed by its arguments. Configure lifetime with cacheLife('hours') and invalidation with cacheTag('x'). It works for any async work (ORM queries), not just fetch. You cannot read cookies/headers inside it; pass values in as arguments.