Request memoization: is fetch Always Memoized or Only with force-cache in Next.js 15? #76254
Replies: 2 comments 7 replies
-
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.
-
I am creating an application and I have the same doubt. Based on my tests (which may not be entirely accurate since I don't have the expertise to be certain), it seems that you don't need to send the "force-cache" parameter. When I make several requests from the client without this parameter, the network inspector shows that each request is cached and returns a 304 response. This leads me to believe that request memoization is working. I hope someone can help clarify whether I'm correct. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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