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

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

第 9 / 23 段:如何控制全路由缓存?

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

如何控制全路由缓存?

让页面被缓存(静态化)

方法 1:使用 revalidate 配置

// app/blog/page.tsx
// 页面级别的 revalidate:每小时重新生成
export const revalidate = 3600;

export default async function BlogPage() {
  const res = await fetch("https://api.example.com/posts");
  const posts = await res.json();
  return <div>...</div>;
}

方法 2:在 fetch 中声明缓存

// 显式声明 force-cache(Next.js 15+ 需要显式声明)
const res = await fetch("https://api.example.com/posts", {
  cache: "force-cache",
});

方法 3:使用 generateStaticParams 预渲染动态路由