1. Next.js App Router Complete Guide Data Fetching編
  2. Next.js App Router Complete Guide Functions編

fetch API編


force cache

- // 'force-cache' is the default, and can be omitted
- fetch('https://...', { cache: 'force-cache' })

revalidate cache

  1. Time-based Revalidation fetchの引数に秒数で指定する。今回は、3600秒なので1時間はデータを再取得しない。
fetch('https://...', { next: { revalidate: 3600 } })

page.tsxやlayoutページで以下のように設定すると、そのページのfetch すべてが上記と同じ設定になる。 fetchに指定されている場合は、上書きされるのではなく一番小さい値が設定される。