use cache Directive & Dynamic IO Runtime Boundaries
- Last updated
- Prerequisites:
- React Server Components
- Next.js App Router Caching
- nextjs
- use-cache
- dynamic-io
- caching
- react
- app-router
Read at your depth
The practical view
In Next.js 15, Dynamic IO (`experimental.dynamicIO: true`) changes the default caching model: all data fetching and rendering is dynamic by default. To cache a function or component, you explicitly annotate it with the `'use cache'` directive. You can customize the cache lifetime using `cacheLife()` and tag it using `cacheTag()`.
The same idea in other frameworks
React `cache()` function for per-request deduplication.RxJS `shareReplay(1)` or custom HTTP caching interceptors.Nuxt `useAsyncData` with explicit cache keys.SvelteKit server-side memory caching via Redis/LRU in `+page.server.ts`.Legacy vs modern
Implicit Fetch Caching vs Explicit 'use cache'
Next.js 14 implicitly cached `fetch`; Next.js 15 Dynamic IO requires explicit opt-in via `'use cache'`.
const res = await fetch(url); // ❌ OLD: Implicitly cached by default'use cache';
import { cacheLife, cacheTag } from 'next/cache'; // ✅ NEWInterview gotchas
Context
Interviewers test your awareness of the architectural shift from implicit to explicit caching.
The mechanical answer
In Next.js 13 and 14, `fetch` requests were cached by default (`force-cache`), which caused confusion and unexpected stale data in dynamic applications. Next.js 15 introduced Dynamic IO and `'use cache'` to make caching opt-in, explicit, and applicable to *any* asynchronous operation (like direct database queries via Prisma or Drizzle), not just the `fetch` API.
Trap
Do not state that `'use cache'` only works on `fetch()` calls. It can cache any async JavaScript function or React Server Component.
Context
This tests component-level caching vs function-level caching.
The mechanical answer
Yes. When `'use cache'` is placed at the top of an async Server Component, Next.js caches the rendered React Server Component output (Flight payload) for the given set of props, avoiding re-rendering the component until revalidated.
Trap
Props passed to a cached component must be serializable so Next.js can generate a deterministic cache key.