How should caching and revalidation work?
Practice this questionWANT TO UNDERSTAND THE CONCEPT FIRST?Learn How should caching and revalidation work?
Definition:
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.
Key points:
-
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.
Interview point:
- Explain exactly what is cached, who may reuse it and what event makes it stale.
Adapted from 06_REACT_NEXTJS.md · “How should caching and revalidation work?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.