HTML 原文 · 完整 Markdown · 纯文本 · 分段目录 · ← 上一段 · 下一段 →

04-第 3 层:全路由缓存 (Full Route Cache)

第 5 / 23 段:工作原理

Next.js 缓存机制全解析 · 发布 2026-02-20 · 更新 2026-11-11 · 标签:Next.js、缓存、前端架构、React

工作原理(续)

sequenceDiagram
    participant U1 as 用户1
    participant U2 as 用户2
    participant U3 as 用户N
    participant FS as 文件系统缓存
    participant React as React 渲染引擎

    U1->>FS: 访问 /blog
    FS-->>U1: 返回 blog.html(不渲染)

    U2->>FS: 访问 /blog
    FS-->>U2: 返回 blog.html(不渲染)

    U3->>FS: 访问 /blog
    FS-->>U3: 返回 blog.html(不渲染)

    Note over React: React 渲染引擎完全空闲<br/>CPU 开销为零

动态页面(不会被缓存)

使用了动态函数的页面会被标记为动态,每次请求都重新渲染:

// app/profile/page.tsx
import { cookies } from "next/headers";

export default async function ProfilePage() {
  // 使用了动态函数 → 页面变成动态的
  const token = (await cookies()).get("token")?.value;

  const res = await fetch("https://api.example.com/user/me", {
    headers: { Authorization: `Bearer ${token}` },
  });

  const user = await res.json();

  return <div>{user.name}</div>;
}