From c6c3ee726dd2e2aaa43879e8442206c38e16c49f Mon Sep 17 00:00:00 2001 From: Tofugrass Date: Mon, 27 Jan 2025 13:52:42 -0600 Subject: [PATCH] Fix: 'force-dynamic' does not opt out of the data cache https://nextjs.org/docs/app/building-your-application/caching#segment-config-options Setting fetchCache = 'default-no-store' opts out of the data cache. I tested and confirmed this behavior live on my web app. A page with dynamic = "force-dynamic" that uses unstable_cache will read the cached value (data cache) without calling the async fetcher function until the key has been invalidated (and purged). The only difference 'force-dynamic' caused on my page was disable the full route cache, forcing the page to re-check the data cache. With tag-based invalidation, only the invalidated tags in the data cache had their fetch functions called. i.e. 'force-dynamic' does not opt out of the data cache --- docs/01-app/03-building-your-application/04-caching/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/01-app/03-building-your-application/04-caching/index.mdx b/docs/01-app/03-building-your-application/04-caching/index.mdx index 434357efa6e67..8f5327256587a 100644 --- a/docs/01-app/03-building-your-application/04-caching/index.mdx +++ b/docs/01-app/03-building-your-application/04-caching/index.mdx @@ -307,7 +307,7 @@ There are two ways you can invalidate the Full Route Cache: You can opt out of the Full Route Cache, or in other words, dynamically render components for every incoming request, by: - **Using a [Dynamic API](#dynamic-apis)**: This will opt the route out from the Full Route Cache and dynamically render it at request time. The Data Cache can still be used. -- **Using the `dynamic = 'force-dynamic'` or `revalidate = 0` route segment config options**: This will skip the Full Route Cache and the Data Cache. Meaning components will be rendered and data fetched on every incoming request to the server. The Router Cache will still apply as it's a client-side cache. +- **Using the `dynamic = 'force-dynamic'` or `revalidate = 0` route segment config options**: This will skip the Full Route Cache. Meaning components will be rendered and data fetched on every incoming request to the server. The Router Cache will still apply as it's a client-side cache. - **Opting out of the [Data Cache](#data-cache)**: If a route has a `fetch` request that is not cached, this will opt the route out of the Full Route Cache. The data for the specific `fetch` request will be fetched for every incoming request. Other `fetch` requests that do not opt out of caching will still be cached in the Data Cache. This allows for a hybrid of cached and uncached data. ## Client-side Router Cache