LESSON 06 / 9·2 min readIntermediate

How should caching and revalidation work?

Try code in the playground
01 Understand02 Recall03 Prepare

Understand the concept

Caching saves a previously computed or fetched result so it can be reused, while revalidation refreshes or invalidates that stored result. A cache design needs a key, a freshness rule and a plan for changes. In Next.js there can be several caching layers, so one invalidation mechanism may not describe every layer's behavior.

Important ideas

  • Decide which data may be cached, for how long, and for which user or tenant.

  • Invalidate affected data after writes; never share private results across users.

  • Next.js defaults vary by version and router, so check the project's actual configuration.

  • After a mutation, identify which pages or data keys depend on it instead of clearing unrelated cached data blindly.

PAUSE & RECALL

Can you explain it without the notes?

How should caching and revalidation work?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Caching saves a previously computed or fetched result so it can be reused, while revalidation refreshes or invalidates that stored result. A cache design needs a key, a freshness rule and a plan for changes. In Next.js there can be several caching layers, so one invalidation mechanism may not describe every layer's behavior.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • Explain exactly what is cached, who may reuse it and what event makes it stale.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: How do I prevent stale search results?

Adapted from 06_REACT_NEXTJS.md · “How should caching and revalidation work?”. Examples are study fragments; framework behavior can depend on your version.