How should caching and revalidation work?
Try code in the playgroundUnderstand 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.
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.
Turn this concept into a clear answer.
- 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?”. Examples are study fragments; framework behavior can depend on your version.