#i get cache: MISS in development

1 messages · Page 1 of 1 (latest)

manic lagoon
#

all my fetches i cache:miss in development

gleaming jungleBOT
#

Hi @manic lagoon. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

In Next.js, all fetch() requests are cached and deduplicated automatically by default. This means that if you make the same request twice, the second request will reuse the result from the first request. However, there are certain conditions where requests are not cached:

  • Dynamic methods (next/headers, export const POST, or similar) are used and the fetch is a POST request (or uses Authorization or cookie headers)
  • fetchCache is configured to skip cache by default
  • revalidate: 0 or cache: 'no-store' is configured on individual fetch

Here's an example of how fetch requests are cached:

async function getComments() {
 const res = await fetch('<https://...'>) // The result is cached
 return res.json()
}
 
// This function is called twice, but the result is only fetched once
const comments = await getComments() // cache MISS
 
// The second call could be anywhere in your application
const comments = await getComments() // cache HIT

If you're seeing cache:miss for all your fetches, it's possible that one of the conditions for not caching is being met. You might want to check your fetchCache configuration or the individual fetch configurations in your code.

You can also control the revalidation frequency of the request by specifying a revalidate option:

export default async function Page() {
 // revalidate this data every 10 seconds at most
 const res = await fetch('<https://...',> { next: { revalidate: 10 } })
 const data = res.json()
 // ...
}

For more information, you can refer to the Next.js documentation on data fetching and caching (https://nextjs.org/docs/app/building-your-application/data-fetching/caching).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: