Next.js unifies data fetching and caching at the framework level, optimized for performance and developer experience in the App Router.
In modern Next.js (App Router), data fetching and caching are built directly into the framework, eliminating manual implementation common in traditional React apps.
Without Caching
Every request → DB/API call → Slow + Expensive. Backend becomes a bottleneck as users scale.
With Caching
First request → Fetch → Cache.
Next requests → Serve from cache → Fast ⚡.
Next.js utilizes multiple specialized layers to maximize performance and minimize infrastructure costs:
What it is
Same request in a single render tree is executed only once.
Example
Flow
Benefit
✔ Avoid duplicate API calls | ✔ Faster rendering
What it is
Persistent cache across requests (server-side).
Example
Flow
Benefit
✔ Reduces backend load | ✔ Improves response time
What it is
Entire page HTML is cached for high-speed delivery.
Used in: SSG, ISR
Flow
Benefit
✔ Instant load time | ✔ Zero server work per request
What it is
Cache stored geographically closer to users.
Flow
Benefit
✔ Ultra-low latency | ✔ Global scalability
Key Change (VERY IMPORTANT)
Next.js has deprecated getServerSideProps and getStaticProps. Data is now fetched directly inside components using async/await.
async function Page() {
const res = await fetch("https://api.com/data");
const data = await res.json();
return <div>{data.name}</div>;
}Automatic caching (SSG-like). Same data served consistently.
Strict static serving. Ensures data remains cached.
Always fresh data (SSR-like). Bypasses cache entirely.
Time-based update (ISR). Refresh every N seconds.
| Fetch Strategy | Cache Result | Typical Use Case |
|---|---|---|
| force-cache | yes | Static documentation, blog posts |
| no-store | No | Real-time stock prices, banking dashboards |
| revalidate | Partial | E-commerce product listings, news feeds |
Definition
Update cached data after deployment without rebuilding the entire site. Combines speed with freshness.
"Combines the static speed of SSG with the data freshness of SSR."
Auto-refresh after a specific time window.
Invalided cache manually via triggers (e.g. Webhooks).
Caches are great until the underlying data changes. Delivering outdated information to users is a critical system failure.
1. Time-based Expiry
Low precision. Good for high-traffic public feeds.
2. Tag-based Invalidation
High precision. Pure system design gold for e-commerce and dynamic apps.
// Fetching with a tag
fetch(url, {
next: { tags: ["products"] }
});
// Implementation: Action Invalidation
import { revalidateTag } from 'next/cache';
async function updateProduct() {
await db.update();
// Clear all cached responses with this tag
revalidateTag("products");
}The server must wait for all data to be fetched before it can send the final HTML. Users see a blank screen for seconds.
Render and send UI in chunks as data arrives. Header and layout arrive instantly; content follows.
import { Suspense } from 'react';
import { ProductList, Skeleton } from './components';
export default function Page() {
return (
<section>
<h1>New Arrivals</h1>
{/* Component rendered on server, streamed through fallback */}
<Suspense fallback={<Skeleton />}>
<ProductList />
</Suspense>
</section>
);
}// Waterfall: B waits for A to finish
const user = await fetch(urlA);
const posts = await fetch(urlB);Total time: A + B
// Simultaneous Execution
const [user, posts] = await Promise.all([
fetch(urlA),
fetch(urlB)
]);Total time: Max(A, B)
DATA
Info
SSG / ISRDATA
Reviews
ISR (60s)DATA
Cart Info
no-store (SSR)Insight: Different parts of the same page can use completely different caching strategies.
Using no-store everywhere kills the edge-caching benefits and spikes server load.
Caching real-time data like stock prices for too long leads to stale, invalid UI.
Forgetting to revalidate after updates causes users to see outdated info indefinitely.
Static Content
Semi-Dynamic
Strict Dynamic
Next.js provides built-in caching and data-fetching mechanisms that allow developers to control performance and freshness.
Scalability + Speed + Freshness