Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 20.5 — Data and Caching in Next.js
React · Example 2 of 3

Sequential awaits vs Promise.all

The same rule as Topic 14.1, now inside an async server component: each await pauses the function, so independent requests should start before you wait.

In Next.js 16 server components await their data directly; with Cache Components enabled you cache functions or components with "use cache", set lifetimes with cacheLife, tag them with cacheTag and refresh them with revalidateTag, updateTag or revalidatePath, while request-time data streams behind <Suspense>, so one route can be part static, part dynamic.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a cached getCategory(slug) that lasts a day and can be refreshed by the tag categories.

02

A product page shows product details (same for everyone) and "Recently viewed" (from a cookie). Write the page so the details are in the static shell.

Explain it without notes

01

How do you fetch data in a Next.js server component, and how do you avoid waterfalls?

02

What makes part of a route dynamic, and how does Cache Components handle it?

03

Explain "use cache", cacheLife and cacheTag. What is part of the cache key?

04

Compare revalidateTag, updateTag and revalidatePath.

Sequential awaits vs Promise.all

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

Sequential (a waterfall):
  start artist
  end artist
  start albums
  end albums
Parallel (start both, then await):
  start artist
  start albums
  end artist
  end albums
A. R. Rahman [ 'Roja', 'Lagaan' ]