React cache
A React function that wraps another function so repeated calls with the same arguments during one server request reuse the first result.
In more detail
Wrap database helpers such as getUser in cache so several Server Components can call them without extra queries. The cache is cleared after each request, so it never serves one user's data to another.
Example
import { cache } from 'react';
export const getUser = cache(async (id: string) => db.user.findUnique({ where: { id } }));Related terms
- Request Memoization — The first Next.js caching tier: identical fetch calls made while rendering one request are run only once.
- memoization — Remembering the result of a calculation for given inputs and reusing it when the same inputs come again, instead of recalculating.
- preloading pattern — Starting a data request early, before the component that needs it renders, so the result is ready or nearly ready when it is used.
Taught in
- Async Data Fetching: Parallel Requests & Preloading — Next.js 15 & Modern App Router Architecture
- Request Memoization: Automatic Deduplication Tiers — Next.js 15 & Modern App Router Architecture