🎓 A1Learner
🔍
0 of 50 lessons completed

Next.js The Three Caches

Next.js remembers answers in three places on the server. It remembers one more place in the browser.

The cached row in the route table

The row shows 1h fresh and 1d kept. The next lesson sets the fresh time.

npm run build

The four caches, listed

Four names hold the whole map. Three live on the server, and one lives in the browser.

const caches = ["Request memoisation", "Data Cache", "Full Route Cache", "Router Cache"];
console.log("Caches:", caches.length);

Example

node -e 'const caches=[["Request memoisation","one request"],["Data Cache","one server"],["Full Route Cache","one build"],["Router Cache","one browser"]]; caches.forEach(c=>console.log(c[0]+" remembers for "+c[1]+"."));'

Key points

  • Request memoisation: one request. The same fetch twice in one render runs once.
  • Data Cache: one server. Fetch results are kept across requests.
  • Full Route Cache: one build. Whole pages are kept until they are revalidated.
  • Router Cache: one browser. Pages the reader already visited load from memory.
  • The cached page shows 1h and 1d in the route table. One hour fresh, one day kept.

In this example, the list holds the four caches. Each row names one cache and how long it remembers. Request memoisation remembers for one request. The Data Cache remembers for one server. The Full Route Cache remembers for one build. The Router Cache remembers for one browser. Four places, four lifetimes. The first three live on the server, and the last one lives in the browser.

Note

A cached page can show old data. Freshness is a choice you make per page.

Try it Yourself

Edit the code, then press Run.

Running is simulated · TypeScript Playground

Exercise

Which cache lives in the browser?