网页
综合
更新时间 2026-11-06 00:00:00
unstable_cache
自动蜘蛛
nextjs.org
正文约 1281 字
For most use cases, use cache replaces this API in Next.js 16. We recommend opting into Cache Components and migrating to the use cache directive.
Continue using unstable_cache for non-fetch data that must persist across deployments. Cached entries from use cache and use cache: remote do not carry over to a new deployment because their cache keys include the build ID or deploymentId.
unstable_cache allows you to cache the results of expensive operations, like database queries, and reuse them across multiple requests.
The function passed to unstable_cache cannot depend on the incoming request. Read values from cookies() or headers() before calling the cached function, then pass those values as arguments so they become part of the cache key.
The cached function also cannot:
Perform request-dependent work before calling the cached function. Perform mutations and revalidation afterward from a Server Action or Route Handler.
unstable_cache returns a function that when invoked, returns a Promise that resolves to the cached data. If the data is not in the cache, the provided function will be invoked, and its result will be cached and returned.
Last updated November 6, 2026
Subscribe to our newsletter
Stay updated on new releases and features, guides, and case studies.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。