#does fetch cache error responses
1 messages · Page 1 of 1 (latest)
Hi @last fulcrum. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
By default, Next.js does not cache fetch responses. However, you can opt specific fetch requests into caching by passing the cache: 'force-cache' option. If you want to opt all fetch requests in a layout or page into caching, you can use the export const fetchCache = 'default-cache' segment config option. If individual fetch requests specify a cache option, that will be used instead.
Here is an example of how to use these options:
// To cache a specific fetch request
const b = await fetch('<https://...',> { cache: 'force-cache' }) // Cached
// To cache all fetch requests in a layout or page
export const fetchCache = 'default-cache'
In the case of an error thrown while attempting to revalidate data, the last successfully generated data will continue to be served from the cache. On the next subsequent request, Next.js will retry revalidating the data.
Please note that these behaviors are subject to the settings and configurations of your Next.js application.
Sources:
- Fetch requests (https://nextjs.org/docs/app/api-reference/functions/fetch)
- Incremental Static Regeneration (ISR) (https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration#handling-uncaught-exceptions)