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

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

第 22 / 23 段:实战建议

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

实战建议(续)

// 产品列表:静态 + 按需更新
// app/products/page.tsx
export default async function ProductsPage() {
  const res = await fetch("https://api.example.com/products", {
    next: { tags: ["products"], revalidate: 3600 },
    cache: "force-cache",
  });
  const products = await res.json();
  return <div>...</div>;
}

// 购物车:动态(每个用户不同)
// app/cart/page.tsx
import { cookies } from "next/headers";

export default async function CartPage() {
  const token = (await cookies()).get("token")?.value;
  const res = await fetch("https://api.example.com/cart", {
    headers: { Authorization: `Bearer ${token}` },
  });
  const cart = await res.json();
  return <div>...</div>;
}