Menu

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

使用方法

fetchcache: '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.0unstable_noStoreconnectionに置き換えられました。
v14.0.0unstable_noStoreが導入されました。