Loading...
async function Profile({ id }) {
const getUser = cache((id) => db.user.find(id));
const user = await getUser(id);
return <h1>{user.name}</h1>;
}const getUser = cache((id) => db.user.find(id));
async function Profile({ id }) {
const user = await getUser(id);
return <h1>{user.name}</h1>;
}A module-level cached function is shared by every component in the request, so the same user is fetched only once.
cache() inside a component, creating a new empty cache on each render.cache() is called at module level, not inside a component, so all callers share one cached function.'use client'.cache() shares a result across components during one server request. useMemo stores a value inside one component between its renders.
No. It is meant for Server Components; in Client Components use useMemo or a data library that caches requests.