Nitro Route Rules SWR Cache Invalidation Limits
25.5K reputation · 13 Feb 2025, 09:17 UTC
Stale-While-Revalidate Behavior in Nitro
Nuxt utilizes the Nitro server engine to implement route-level caching via routeRules. When configuring a route with swr (stale-while-revalidate), the server is designed to serve a cached response immediately while triggering a background refresh if the TTL has expired.
Granular Invalidation Constraints
While the swr mechanism ensures high availability and fast response times, it introduces a period where users receive stale data. In standard configurations, Nitro provides mechanisms to clear the cache, but these often operate on a global scale rather than targeting specific paths or dynamic route parameters.
There is uncertainty regarding the ability to trigger a targeted revalidation for a single specific URL without purging the entire server cache, particularly when deploying to self-hosted Node.js environments versus managed platforms.
- How can a specific SWR-cached route be invalidated programmatically without affecting other cached routes?
- Does Nitro support a targeted purge mechanism for dynamic routes using parameters?