Next.js App Router Data Cache and CDN synchronization during revalidation
0 reputation · 09 May 2023, 04:13 UTC
Data Cache Consistency
Next.js App Router utilizes a server-side Data Cache that persists across deployments, managed via revalidatePath and revalidateTag. While these functions purge the internal Next.js cache, the interaction with external Content Delivery Networks (CDNs) introduces a synchronization boundary.
CDN Integration Constraints
When utilizing complex middleware logic to handle request routing or custom headers, the timing between the server-side cache purge and the CDN's edge cache expiration can vary. This creates a window where the origin server has updated data, but the edge continues to serve a stale version of the page.
Given the server-first architecture of the App Router, it is unclear how to ensure an atomic update across both the internal Data Cache and an external CDN without relying on short TTLs that negate the benefits of caching.
- How does the
revalidateTagmechanism signal external CDN purges in a standard deployment? - What is the recommended strategy for synchronizing the Next.js Data Cache with edge-cached responses when using custom middleware?