dynamicIO
dynamicIO
标志是 Next.js 中的一项实验性功能,它会导致 App Router 中的数据提取操作被排除在预渲染之外,除非它们被明确缓存。这对于优化服务器组件中动态数据获取的性能很有用。
¥The dynamicIO
flag is an experimental feature in Next.js that causes data fetching operations in the App Router to be excluded from pre-renders unless they are explicitly cached. This can be useful for optimizing the performance of dynamic data fetching in server components.
如果你的应用需要在运行时提取新数据,而不是从预渲染的缓存中提供服务,那么它很有用。
¥It is useful if your application requires fresh data fetching during runtime rather than serving from a pre-rendered cache.
它预计会与 use cache
结合使用,这样除非你在页面、函数或组件级别定义要使用 use cache
缓存的应用特定部分,否则默认情况下数据提取会在运行时进行。
¥It is expected to be used in conjunction with use cache
so that your data fetching happens at runtime by default unless you define specific parts of your application to be cached with use cache
at the page, function, or component level.
用法
¥Usage
要启用 dynamicIO
标志,请在 next.config.ts
文件的 experimental
部分中将其设置为 true
:
¥To enable the dynamicIO
flag, set it to true
in the experimental
section of your next.config.ts
file:
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
experimental: {
dynamicIO: true,
},
}
export default nextConfig
启用 dynamicIO
后,你可以使用以下缓存功能和配置:
¥When dynamicIO
is enabled, you can use the following cache functions and configurations:
-
¥The
use cache
directive -
cacheLife
功能 与use cache
¥The
cacheLife
function withuse cache
-
¥The
cacheTag
function
注意
¥Notes
-
虽然
dynamicIO
可以通过确保在运行时获取新数据来优化性能,但与提供预渲染内容相比,它也可能会引入额外的延迟。¥While
dynamicIO
can optimize performance by ensuring fresh data fetching during runtime, it may also introduce additional latency compared to serving pre-rendered content.