CoachnestCoachnest
Sign InGet Started
Back to course

Next.js 16: The Complete Developer Guide

…
—
Contents
1

What's New in Next.js 16

Reading14mFree
2

Installation, CLI & Your First Project

Reading12mFree
3

Project Structure & Conventions Deep Dive

Reading16m
4

Turbopack — The New Default Bundler

Video18m
5

Configuring TypeScript, ESLint & next.config.ts

Reading14m
6

Chapter 1 — Quiz

Quiz10m
7

App Router Fundamentals

Reading16m
8

Dynamic Routes, Catch-Alls & Type-Safe Params

Reading14m
9

Route Groups & Parallel Routes

Reading16m
10

Intercepting Routes & Modal Patterns

Reading12m
11

Loading, Error & Not-Found UI

Reading12m
12

Chapter 2 — Routing Quiz

Quiz12m
13

Understanding the Server/Client Boundary

Reading18m
14

Choosing When to use "use client"

Reading14m
15

Composing Server & Client Components

Reading14m
16

server-only, client-only & Code Splitting

Reading12m
17

Chapter 3 — Quiz

Quiz10m
18

Fetching Data in Server Components

Reading14m

The Next.js 16 Cache Model

Reading16m
20

Revalidation: revalidateTag, revalidatePath & On-Demand

Reading12m
21

Cache Components — Building Reusable Cached Functions

Reading14m
22

Search Params, Cookies & Dynamic APIs

Reading12m
23

Chapter 4 — Quiz

Quiz12m
24

Server Actions From First Principles

Reading16m
25

Forms with useActionState & Progressive Enhancement

Reading14m
26

Optimistic UI with useOptimistic

Reading12m
27

Validation with Zod + Server Actions

Reading12m
28

Chapter 5 — Quiz

Quiz10m
29

Static vs Dynamic vs Streaming

Reading14m
30

generateStaticParams & Pre-Rendering Dynamic Routes

Reading12m
31

Incremental Static Regeneration (ISR)

Reading12m
32

Partial Prerendering (PPR)

Reading16m
33

Edge Runtime vs Node.js Runtime

Reading12m
34

Rendering Strategies Deep Dive

Video22m
35

Chapter 6 — Quiz

Quiz12m
36

Tailwind CSS v4 with Next.js 16

Reading14m
37

CSS Modules, Global Styles & Scoped CSS

Reading10m
38

next/image — Smart, Fast Images

Reading14m
39

Fonts, Icons & Metadata

Reading12m
40

Chapter 7 — Quiz

Quiz10m
41

Middleware Fundamentals

Reading14m
42

Sessions, JWTs & Cookies

Reading16m
43

Protecting Server Components & Server Actions

Reading12m
44

Chapter 8 — Quiz

Quiz10m
45

Prisma with Next.js — The Production Setup

Reading14m
46

Mutations: Server Actions + Database Writes

Reading12m
47

Route Handlers & REST APIs

Reading12m
48

Chapter 9 — Quiz

Quiz10m
49

Unit & Component Testing with Vitest

Reading12m
50

End-to-End Testing with Playwright

Reading14m
51

Deploying to Vercel

Reading12m
52

Self-Hosting with Docker

Reading14m
53

Production Performance Checklist

Reading12m
54

Final Assessment — Next.js 16 Mastery

Quiz20m
←→navigate lessons
Chapter 4 of 10·Chapter 4 — Data Fetching & The Next.js 16 Cache Model
Lesson 19 of 54Reading16 min

The Next.js 16 Cache Model

#The Next.js 16 Cache Model¶

Next.js 16 introduces an opt-in caching model. By default nothing is cached — you cache deliberately, with "use cache" + cacheTag + cacheLife.

The Old Model (Pre-15) vs the New Model¶

OldNew (16)
Defaultfetch was cached foreverfetch is uncached
Opt-in cachefetch(url, { next: { revalidate } })"use cache" directive
InvalidationrevalidatePath / revalidateTagrevalidateTag(tag) (still works)
PurposeFull route cachingCache any function or component

Why the change? The old model conflated "is this request cached?" with "is this route static?" — leading to surprising production behavior. The new one is explicit.

"use cache" — The Core Primitive¶

Add the directive at the top of a function or file:

ts
7 lines
1// lib/data/courses.ts
2"use cache";
3import { db } from "@/lib/db";
4
5export async function getPublishedCourses() {
6  return db.course.findMany({ where: { status: "PUBLISHED" } });
7}

Calling getPublishedCourses() from anywhere — a Server Component, an API route, a Server Action — returns the cached value when the cache is warm and fresh.

cacheTag — Tag It For Invalidation¶

ts
7 lines
1"use cache";
2import { cacheTag } from "next/cache";
3
4export async function getCourse(slug: string) {
5  cacheTag("course", `course:${slug}`);
6  return db.course.findUnique({ where: { slug } });
7}

Now you can revalidate every cached entry for that course with one call:

ts
2 lines
1import { revalidateTag } from "next/cache";
2revalidateTag(`course:${slug}`);

Or wipe all cached courses:

ts
1 line
1revalidateTag("course");

cacheLife — How Long Things Stay Fresh¶

ts
7 lines
1"use cache";
2import { cacheLife } from "next/cache";
3
4export async function getHomeFeed() {
5  cacheLife("minutes");      // alias for { stale: 60s, revalidate: 5min, expire: 30min }
6  return /* … */;
7}

Named profiles:

ProfileStaleRevalidateExpire
"seconds"01s60s
"minutes"60s5m30m
"hours"5m1h1d
"days"5m12h7d
"weeks"1h1d30d
"max"5m1y1y

Custom values:

ts
1 line
1cacheLife({ stale: 30, revalidate: 300, expire: 3600 });

Stale-While-Revalidate Semantics¶

The terminology matters:

  • stale — within this window, serve from cache and don't re-fetch
  • revalidate — after this window, serve from cache and trigger a background re-fetch
  • expire — after this window, the entry is gone; the next request blocks for a fresh fetch

This is the same model CDNs use for Cache-Control: stale-while-revalidate.

Caching a Whole Page¶

tsx
9 lines
1// app/(marketing)/page.tsx
2"use cache";
3import { cacheLife } from "next/cache";
4
5export default async function Home() {
6  cacheLife("hours");
7  const posts = await db.blog.findMany({ take: 6 });
8  return <Hero posts={posts} />;
9}

Caching a Single Component¶

tsx
10 lines
1// components/Reviews.tsx
2"use cache";
3import { cacheTag, cacheLife } from "next/cache";
4
5export async function Reviews({ courseId }: { courseId: string }) {
6  cacheTag(`reviews:${courseId}`);
7  cacheLife("hours");
8  const reviews = await db.review.findMany({ where: { courseId } });
9  return /* … */;
10}

The page can be uncached while only the Reviews block is cached — a form of partial caching that the old model never made easy.

Previous

Fetching Data in Server Components

Next

Revalidation: revalidateTag, revalidatePath & On-Demand

Use ← → arrow keys to navigate between lessons