staleTimes
staleTimes
是一项实验性功能,用于在客户端路由缓存中缓存页面片段。
您可以通过设置实验性的 staleTimes
标志来启用此功能并提供自定义重新验证时间:
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
staleTimes: {
dynamic: 30,
static: 180,
},
},
}
module.exports = nextConfig
static
和 dynamic
属性根据不同类型的链接预取对应不同的时间周期(以秒为单位)。
dynamic
属性用于页面既非静态生成也未被完全预取的情况(例如prefetch={true}
)- 默认值:0 秒(不缓存)
static
属性用于静态生成的页面,或当Link
组件的prefetch
属性设为true
时,或调用router.prefetch
时- 默认值:5 分钟
须知:
您可以在此处了解更多关于客户端路由缓存的信息。
版本历史
版本 | 变更内容 |
---|---|
v15.0.0 | dynamic 的 staleTimes 默认值从 30 秒改为 0 秒 |
v14.2.0 | 引入实验性 staleTimes 功能 |