Skip to main content

expireTime

你可以在启用 ISR 的页面的 Cache-Control 标头中指定 CDN 使用的自定义 stale-while-revalidate 过期时间。

¥You can specify a custom stale-while-revalidate expire time for CDNs to consume in the Cache-Control header for ISR enabled pages.

打开 next.config.js 并添加 expireTime 配置:

¥Open next.config.js and add the expireTime config:

module.exports = {
// one hour in seconds
expireTime: 3600,
}

现在,发送 Cache-Control 标头时,过期时间将根据特定的重新验证期计算。

¥Now when sending the Cache-Control header the expire time will be calculated depending on the specific revalidate period.

例如,如果你对路径进行了 15 分钟的重新验证,并且过期时间为一小时,则生成的 Cache-Control 标头将是 s-maxage=900, stale-while-revalidate=2700,以便它可以比配置的过期时间少 15 分钟保持陈旧状态。

¥For example, if you have a revalidate of 15 minutes on a path and the expire time is one hour the generated Cache-Control header will be s-maxage=900, stale-while-revalidate=2700 so that it can stay stale for 15 minutes less than the configured expire time.