Q51: What is React's built-in `cache()` function and how is it used in Server Components?
React's cache() function allows memoizing data fetching or computation per request cycle in React Server Components (RSC). When the same function is invoked multiple times with identical arguments within a single server request, cache() executes the function once and returns the cached result for subsequent calls, preventing duplicated network requests or database queries during rendering.
Key Takeaways
cache()deduplicates data fetches and heavy computations per server request cycle in RSC.- Scoped strictly to the duration of a single request, preventing cross-request data leaks.
Knowledge Check
What scope does React's cache() function apply to when used inside Server Components?