- All Courses
- Next.js for Production
- Data Fetching and Caching
- Request memoization and the data cache
Request memoization and the data cache
Request memoization deduplicates identical fetches within a single render pass.
Overview
Two different caches with two different lifetimes
Request memoization deduplicates identical fetches within a single render pass. Ten components asking for the same user produce one request. It lives and dies with the request and has no configuration.
The data cache is persistent: it survives across requests and deployments until something invalidates it. This is the one that serves a visitor content fetched an hour ago.
When a page shows stale data, work out which cache is responsible before changing anything. Memoization cannot serve stale content across requests, so persistent staleness is always the data cache or a caller that opted into it.
- Use no-store for data that must be fresh on every request
- Set a revalidate window for data that can be a little behind
- Tag a fetch when you want to invalidate it by name later
In this lesson you will:
- Separate per-request deduplication from persistent caching
- Opt a fetch out of the cache deliberately
- Recognise which cache is serving stale data
Resources
Notes are not saved yet — they clear when you leave this page.
Fetching data in Server Components
4m
Revalidation: time-based and on-demand
17m