Mastering the Next.js Caching System
Next.js aggressively caches everything by default to ensure pages load instantly, but understanding how to bust that cache is critical.
- Data Cache: Next.js extends the native
fetchAPI to memorize requests across the server. You can control this usingrevalidatetags or time-based expiration. - Full Route Cache: Entire pages are rendered to static HTML and JSON at build time. Dynamic functions (like reading cookies or headers) will automatically opt the route out of this cache.
- Router Cache: The client-side browser caches React Server Component payloads for seamless navigation. Calling
revalidatePathorrevalidateTagis required to force the client to fetch fresh UI.