Lesson 2.2

Request memoization and the data cache

Request memoization deduplicates identical fetches within a single render pass.

6mIntermediate14.5k students

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

Previous Lesson
Next Lesson
Request memoization and the data cache — Next.js for Production — Vertex