Skip to content

Next 15 でキャッシュを有効化できない #92

@wand2016

Description

@wand2016

環境

  • next: 15.3.1
  • microcms-js-sdk 3.2.0

背景

関連: #53

Next 15 でキャッシュの挙動に破壊的変更が入り、 fetch 結果がデフォルトでキャッシュされなくなりました。
以前のバージョンのように fetch の結果をキャッシュするには、2025/5/6現在、以下のいずれかの対応が必要になります:

  • 'use cache' ディレクティブを使用する (canary バージョンのみ)
  • fetchcache: 'force-cache' option を渡す

参考: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching#reusing-data-across-multiple-functions

問題

下記のように SDK の customRequestInit オプションを用いて fetchcache オプションに 'force-cache' を渡しました。

// ブログ一覧を取得
export const getList = async (queries?: MicroCMSQueries) => {
  const listData = await client
    .getList<Blog>({
      endpoint: 'blog',
      queries,
      customRequestInit: {
        cache: 'force-cache',
      },
    })
    .catch(notFound);
  return listData;
};

しかし、 next dev でローカル開発サーバーを起動し Next の cache のログを見ると、キャッシュがスキップされていました。

 │ GET https://<domain>.microcms.io/api/v1/tags?limit=10 200 in 169ms (cache skip)
 │ │ Cache skipped reason: (cache-control: no-cache (hard refresh))
 │ GET https://<domain>.microcms.io/api/v1/blog/btezx8p6a82 200 in 165ms (cache skip)
 │ │ Cache skipped reason: (cache-control: no-cache (hard refresh))
 │ GET https://<domain>.microcms.io/api/v1/blog/btezx8p6a82 200 in 147ms (cache skip)
 │ │ Cache skipped reason: (cache-control: no-cache (hard refresh))

参考: https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration#troubleshooting

質問

Next 15 でキャッシュを効かせる方法はありますか。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions