主题
staleTimes
staleTimes 是一项实验性功能,可在 客户端路由缓存 中启用页面段的缓存。
¥staleTimes is an experimental feature that enables caching of page segments in the client-side router cache.
你可以通过设置实验性的 staleTimes 标志来启用此实验性功能并提供自定义重新验证时间:
¥You can enable this experimental feature and provide custom revalidation times by setting the experimental staleTimes flag:
static 和 dynamic 属性对应于基于不同类型的 链接预取 的时间段(以秒为单位)。
¥The static and dynamic properties correspond with the time period (in seconds) based on different types of link prefetching.
当页面既不是静态生成的也不是完全预取的(例如使用
prefetch={true})时,使用dynamic属性。¥The
dynamicproperty is used when the page is neither statically generated nor fully prefetched (e.g. withprefetch={true}).默认:0 秒(未缓存)
¥Default: 0 seconds (not cached)
static属性用于静态生成的页面,或者当Link上的prefetch属性设置为true时,或者调用router.prefetch时。¥The
staticproperty is used for statically generated pages, or when theprefetchprop onLinkis set totrue, or when callingrouter.prefetch.默认:5 分钟
¥Default: 5 minutes
需要了解:
¥Good to know:
加载边界 被认为在此配置中定义的
static周期内可重复使用。¥Loading boundaries are considered reusable for the
staticperiod defined in this configuration.这不会影响 部分渲染,这意味着共享布局不会在每次导航时自动重新获取,只会重新获取发生变化的页面段。
¥This doesn't affect partial rendering, meaning shared layouts won't automatically be refetched on every navigation, only the page segment that changes.
这不会改变 后退/前进缓存 行为以防止布局偏移并防止丢失浏览器滚动位置。
¥This doesn't change back/forward caching behavior to prevent layout shift and to prevent losing the browser scroll position.
你可以了解有关客户端路由缓存 此处 的更多信息。
¥You can learn more about the Client Router Cache here.
版本历史
¥Version History
| 版本 | 更改 |
|---|---|
v15.0.0 | dynamic staleTimes 默认值从 30 秒更改为 0 秒。 |
v14.2.0 | 引入了实验性 staleTimes。 |