new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Next.js App Router · all subjects

data-fetching-caching/reusing-data

4 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

React.cache for reusing data

Wrap a data-fetching function in React.cache() so multiple components in the same request share one result instead of refetching. Import cache from 'react' and wrap your async function: export const getUser = cache(async () => { ... })

React.cache memoization example

Example: import { cache } from 'react', then export const getUser = cache(async () => { const res = await fetch(...); return res.json() }). Server Components can call getUser() directly and multiple calls within the same request return the same memoized result.

React.cache is request-scoped

React.cache is scoped to the current request only. Each request gets its own memoization scope with no sharing between requests. This prevents stale data across different user sessions.

Memoization of fetch requests in Next.js

Memoization caches the return value of a function so calling the same function multiple times during a render pass only executes it once. In Next.js, fetch GET requests with the same URL and options are automatically memoized across Server Components, layouts, pages, and generateMetadata/generateStaticParams, but not Route Handlers since they are not part of the React component tree. For non-fetch operations, use the React cache function.

Give your agent this brain