You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Background
Previously we introduced automatic caching for `fetch` based on certain
heuristics that were a bit tricky to grasp all scenarios. The scenarios
we would automatically cache were no dynamic data access before the
fetch call e.g. `headers()` or `cookies()`, the fetch call is inside of
a dynamic page e.g. `POST` method or `export const revalidate = 0` page
and the fetch is a non-`GET` request or has `Authorization` or `Cookie`
headers, or the fetch had `cache: 'no-store' | 'no-cache'` or
`revalidate: 0`.
## New Behavior
By default fetches will no longer automatically be cached. Instead they
need to be opted-in to caching via `export const fetchCache =
'default-cache' | 'force-cache',` `next: { revalidate: false or value >
0 }` or `cache: 'force-cache' | 'default-cache'`.
When the fetch call is automatically skipping the cache it won't impact
the page level ISR cacheability although if a fetch call manually
specifies `cache: 'no-store'` or `revalidate: 0` it will still bail from
the page being statically generated as it was before.
To achieve the previous behavior of automatic fetch caching all that
needs to be added is `export const fetchCache = 'default-cache'` in the
root layout(s) of your project.
`fetch for ${fetchUrl} on ${staticGenerationStore.urlPathname} specified "cache: ${_cache}" and "revalidate: ${curRevalidate}", only one should be specified.`
334
+
`fetch for ${fetchUrl} on ${staticGenerationStore.urlPathname} specified "cache: ${currentFetchCacheConfig}" and "revalidate: ${currentFetchRevalidate}", only one should be specified.`
335
335
)
336
336
}
337
-
_cache=undefined
337
+
currentFetchCacheConfig=undefined
338
338
}
339
339
340
-
if(_cache==='force-cache'){
341
-
curRevalidate=false
340
+
if(currentFetchCacheConfig==='force-cache'){
341
+
currentFetchRevalidate=false
342
342
}elseif(
343
-
_cache==='no-cache'||
344
-
_cache==='no-store'||
345
-
fetchCacheMode==='force-no-store'||
346
-
fetchCacheMode==='only-no-store'||
343
+
currentFetchCacheConfig==='no-cache'||
344
+
currentFetchCacheConfig==='no-store'||
345
+
pageFetchCacheMode==='force-no-store'||
346
+
pageFetchCacheMode==='only-no-store'||
347
347
// If no explicit fetch cache mode is set, but dynamic = `force-dynamic` is set,
348
348
// we shouldn't consider caching the fetch. This is because the `dynamic` cache
349
349
// is considered a "top-level" cache mode, whereas something like `fetchCache` is more
350
350
// fine-grained. Top-level modes are responsible for setting reasonable defaults for the
0 commit comments