Next.js 缓存的前世今生(续)
graph LR
subgraph "App Router:1 个页面 = N 个组件 × N 次数据获取"
Layout[Layout] --> F1[fetch]
Header[Header] --> F2[fetch]
Page[Page] --> F3[fetch]
Sidebar[Sidebar] --> F4[fetch]
Footer[Footer] --> F5[fetch]
end
style F1 fill:#f99,stroke:#333,stroke-width:2px
style F2 fill:#f99,stroke:#333,stroke-width:2px
style F3 fill:#f99,stroke:#333,stroke-width:2px
style F4 fill:#f99,stroke:#333,stroke-width:2px
style F5 fill:#f99,stroke:#333,stroke-width:2px
style F5 fill:#f99,stroke:#333,stroke-width:2px
如果不做缓存,每个用户的每次访问都会触发大量的服务端渲染和数据请求。对于 Vercel 这样按计算量计费的平台来说,这意味着巨大的基础设施成本;对于开发者来说,这意味着响应速度变慢、服务器账单飙升。
这就是 Vercel 在 Next.js 13/14 中选择"默认缓存一切"这个激进策略的根本原因——不是因为他们觉得缓存比新鲜度重要,而是因为 RSC 架构下,不缓存的代价太大了。
社区反弹与 Next.js 15 的修正
但"默认缓存一切"带来了大量的开发者困惑。Vercel 团队在 2024 年 10 月发布了 Our Journey with Caching 一文,坦诚承认了问题: