N Next.js 中文
原文 ↗

unstable_noStore

unstable_noStore 函数的 API 参考。

更新于 2026-03-03Next.js 16.4.6

这是一个旧版 API,不再推荐使用。为了向后兼容,它仍然受支持。

在版本 15 中,我们建议使用 connection 替代 unstable_noStore。

unstable_noStore 可用于以声明式的方式退出预渲染,并指明某个特定组件不应被缓存。

import { unstable_noStore as noStore } from 'next/cache';

export default async function ServerComponent() {
  noStore();
  const result = await db.query(...);
  ...
}

须知:

  • unstable_noStore 在 fetch 上等同于 cache: 'no-store'
  • 相比 export const dynamic = 'force-dynamic',更推荐使用 unstable_noStore,因为它粒度更细,可以按组件使用
  • 在 unstable_cache 内部使用 unstable_noStore 不会退出静态生成。相反,它会遵循缓存配置来决定是否缓存结果。

用法

如果你不想向 fetch 传递额外选项(例如 cache: 'no-store'、next: { revalidate: 0 }),或者在 fetch 不可用的情况下,可以使用 noStore() 作为所有这些用例的替代方案。

import { unstable_noStore as noStore } from 'next/cache';

export default async function ServerComponent() {
  noStore();
  const result = await db.query(...);
  ...
}

版本历史

版本 变更
v15.0.0 弃用 unstable_noStore,改用 connection。
v14.0.0 引入 unstable_noStore。