unstable_noStore

バージョン15では、unstable_noStore の代わりに connection を使用することを推奨します。

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' と同等です
  • unstable_noStore は、export const dynamic = 'force-dynamic' よりも推奨されます。より細かく設定でき、コンポーネントごとに使用できるためです
  • unstable_cache 内で unstable_noStore を使用しても、静的な生成はオプトアウトされません。代わりに、キャッシュの設定に従って結果をキャッシュするかどうかが決定されます

使用方法

cache: 'no-store'next: { revalidate: 0 } のような追加オプションを fetch に渡したくない場合、または fetch が利用できない場合、noStore() をこれらのユースケースすべての代替として使用できます。

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

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

バージョン履歴

バージョン変更内容
v15.0.0unstable_noStore が非推奨となり、connection に置き換えられました
v14.0.0unstable_noStore が導入されました