-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
環境
- next: 15.3.1
- microcms-js-sdk 3.2.0
背景
関連: #53
Next 15 でキャッシュの挙動に破壊的変更が入り、 fetch
結果がデフォルトでキャッシュされなくなりました。
以前のバージョンのように fetch
の結果をキャッシュするには、2025/5/6現在、以下のいずれかの対応が必要になります:
'use cache'
ディレクティブを使用する (canary バージョンのみ)fetch
にcache: 'force-cache'
option を渡す
問題
下記のように SDK の customRequestInit
オプションを用いて fetch
の cache
オプションに '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))
質問
Next 15 でキャッシュを効かせる方法はありますか。
KiichiSugihara
Metadata
Metadata
Assignees
Labels
No labels