mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Follow-up to https://github.com/vercel/next.js/pull/49628 this updates the `export const fetchCache` handling and `cache: 'no-store'` handling as discussed which also aligns with our docs here https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#fetchcache - `export const fetchCache = 'force-cache'`: forces all fetches to be cached regardless of `cache: 'no-store'` but cacheable `revalidate` values still take priority - `export const fetchCache = 'default-cache'`: ensures fetches are cached even if they come after a `cache: 'no-store'` fetch but don't override `cache: 'no-store'` itself. - without `export const fetchCache`, we still disable fetch cache for successive fetches after a fetch that does `cache: 'no-store'` x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1683732826894469)
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
export const fetchCache = 'force-cache'
|
|
|
|
export default async function Page() {
|
|
const dataNoCache = await fetch(
|
|
'https://next-data-api-endpoint.vercel.app/api/random?a1',
|
|
{
|
|
cache: 'no-cache',
|
|
}
|
|
).then((res) => res.text())
|
|
|
|
const dataForceCache = await fetch(
|
|
'https://next-data-api-endpoint.vercel.app/api/random?b2',
|
|
{
|
|
cache: 'force-cache',
|
|
}
|
|
).then((res) => res.text())
|
|
|
|
const dataRevalidateCache = await fetch(
|
|
'https://next-data-api-endpoint.vercel.app/api/random?c3',
|
|
{
|
|
next: {
|
|
revalidate: 3,
|
|
},
|
|
}
|
|
).then((res) => res.text())
|
|
|
|
const dataRevalidateAndFetchCache = await fetch(
|
|
'https://next-data-api-endpoint.vercel.app/api/random?d4',
|
|
{
|
|
next: {
|
|
revalidate: 3,
|
|
},
|
|
cache: 'force-cache',
|
|
}
|
|
).then((res) => res.text())
|
|
|
|
const dataAutoCache = await fetch(
|
|
'https://next-data-api-endpoint.vercel.app/api/random?d4'
|
|
).then((res) => res.text())
|
|
|
|
return (
|
|
<>
|
|
<p>/force-cache</p>
|
|
<p id="data-no-cache">"cache: no-cache" {dataNoCache}</p>
|
|
<p id="data-force-cache">"cache: force-cache" {dataForceCache}</p>
|
|
<p id="data-revalidate-cache">"revalidate: 3" {dataRevalidateCache}</p>
|
|
<p id="data-revalidate-and-fetch-cache">
|
|
"revalidate: 3 and cache: force-cache" {dataRevalidateAndFetchCache}
|
|
</p>
|
|
<p id="data-auto-cache">"auto cache" {dataAutoCache}</p>
|
|
</>
|
|
)
|
|
}
|