Course contentsShow
← React
Lesson 1571 of 2,39638. Server Components FundamentalsFree lesson

Server Component Caching Behavior

How frameworks cache Server Component output and when cached results are reused or invalidated.

Server Component Caching Behavior

You'll learn how frameworks cache Server Component output and when those cached results are reused or invalidated.

When a Server Component renders, it produces RSC wire format output that can be expensive to regenerate—database queries, API calls, and computations all take time. Frameworks like Next.js cache this output to avoid redundant work.

The Caching Mental Model

Think of Server Component caching like a restaurant that remembers completed orders. If someone orders the exact same meal again, the kitchen can serve a pre-made version instantly instead of cooking from scratch. But if any ingredient changes (different props, different data), a fresh meal must be prepared.

When Cached Results Are Reused

The cache key includes:

  • The component's location in the tree
  • The props passed to it
  • The URL/route parameters

If all these match a previous render, the cached output is served immediately. The component doesn't re-execute, and no database queries run again.

When Cache Is Invalidated

Caches typically invalidate when:

  • Time-based: After a configured duration (e.g., 60 seconds)
  • Manual revalidation: Explicit cache-busting API calls
  • Mutation-triggered: Server Actions or API routes that modify data
  • Full navigation: Moving to a different route entirely

The Streaming Caveat

Components wrapped in Suspense boundaries may bypass full caching since they stream progressively. The framework might cache chunks separately or cache the final resolved state only.

Key Takeaway: Server Component output is cached by frameworks to avoid re-executing expensive operations, with cache invalidation triggered by time, mutations, or explicit revalidation—understanding this helps you optimize data freshness vs performance.