Request memoization: is fetch Always Memoized or Only with force-cache in Next.js 15? #76254
Unanswered
Jancaster1234
asked this question in
Help
Replies: 1 comment 1 reply
-
Yeah, some documentation is not fully up-to-date, I think, but let's go off the Next 15 release notes:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
I’m looking for clarification on whether fetch requests are always memoized or if memoization only occurs when explicitly using force-cache in Next.js 15.
In this blog: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching#reusing-data-across-multiple-functions
It states:
"If you are using fetch, requests can be memoized by adding cache: 'force-cache'. This means you can safely call the same URL with the same options, and only one request will be made."
In other blog: https://nextjs.org/docs/app/building-your-application/caching#request-memoization
An example suggests that fetch is automatically memoized, regardless of the cache setting:
async function getItem() {
// The
fetch
function is automatically memoized and the result// is cached
const res = await fetch('https://.../item/1')
return res.json()
}
// This function is called twice, but only executed the first time
const item = await getItem() // cache MISS
// The second call could be anywhere in your route
const item = await getItem() // cache HIT
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions