perf hacks
CachingOverview

The Four Cache Layers

Next.js has four caching layers. Here's the 30-second overview.

Key Insight

Caching is the highest-leverage optimization. A cached response costs nothing. An uncached response runs your function every time.

The Layers

THE CACHE WATERFALLRequestCDN CacheedgeRoute CacheserverData Cachefetch()MemoizationrenderOriginfreecosts $← hit earlier = cheaper →
LayerWhat It CachesCost Impact
CDN CacheFull responses at edgeEliminates function calls
Route CachePre-rendered pagesEliminates SSR
Data Cachefetch() resultsReduces external calls
Request MemoizationDuplicate fetches in renderMinor optimization

Which Layer Is Active?

Check your build output:

npm run build
  • ○ Static - Route Cache active
  • ● SSG with params - Route Cache active
  • ƒ Dynamic - No Route Cache, relies on CDN/Data cache

Cost Impact

ScenarioWithout CachingWith CachingSavings
Product page (10K/day)10K runs24 runs (ISR)99.8%
API endpoint (100K/day)100K runs~300 runs99.7%
Blog post5K runs1 run99.98%

The pattern: anything cacheable should be cached.


Start with CDN Cache for API routes, or Route Cache for pages.

On this page