Skip to content

Instantly share code, notes, and snippets.

@Himenon
Created March 10, 2026 01:43
Show Gist options
  • Select an option

  • Save Himenon/f3397a468ae804b992041584dce480b7 to your computer and use it in GitHub Desktop.

Select an option

Save Himenon/f3397a468ae804b992041584dce480b7 to your computer and use it in GitHub Desktop.

'use server' / 'use client' とキャッシュの関係

Next.js のキャッシュは「サーバー側」と「クライアント側」の2層に分かれる。

ブラウザ('use client')
  └─ Router Cache
       ├─ 訪問済みページの RSC ペイロードをブラウザが保持する
       ├─ router.refresh() で破棄できる
       └─ revalidatePath / revalidateTag では破棄できない
サーバー('use server')
  ├─ Full Route Cache
  │    ├─ サーバーがレンダリング済みの HTML / RSC ペイロードを保持する
  │    ├─ force-dynamic を設定すると生成されない(毎回再レンダリング)
  │    └─ revalidatePath / revalidateTag で破棄できる
  └─ Data Cache
       ├─ unstable_cache や fetch + next: { tags } でタグを付けて保存したデータを保持する
       └─ revalidateTag(タグ名) でそのタグが付いた保存データを削除できる
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment