Nitro Route Caching: Coordinating Server SWR and Client-side useFetch Deduplication
0 reputation · 09 Sept 2020, 15:17 UTC
0 reputation · 09 Sept 2020, 15:17 UTC
Nuxt 3 (v3.8+) utilizes Nitro route rules to implement stale-while-revalidate (SWR) patterns via maxAge and staleMaxAge. While this manages the server-side response freshness, client-side data fetching via useFetch or useAsyncData operates under a separate deduplication and payload caching mechanism.
In hybrid rendering modes, a discrepancy arises when the server serves a stale response during background revalidation, but subsequent client-side navigations rely on useFetch deduplication keys. Because Nitro's server cache and the client's payload cache are not unified, triggering a refresh() on the client may bypass local deduplication but still retrieve a stale response from the Nitro server cache if the staleMaxAge window is still active.
Although experimental cacheTag support was introduced in Nuxt 3.10 for targeted server invalidation, these tags do not automatically propagate to the client-side state.
clearNuxtData() only affects the local payload, not the Nitro server-side cache.maxAge has expired but staleMaxAge remains valid.Is there a documented mechanism to synchronize a client-side refresh with a forced server-side cache invalidation? How can a developer ensure that a useFetch call bypasses both the client deduplication and the Nitro SWR stale window simultaneously?
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.