Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Only use React cache() for calls repeated within a single render/request
Use React cache for supported request-scoped server memoization; do not assume cross-request persistence or that layouts and pages necessarily have separate scopes.
Bad example
| 1 | const getProduct = cache(loadProduct); |
| 2 | // Assumes this result remains cached for all later HTTP requests. |
Explanation (EN)
Request-scoped memoization cannot promise reuse across independent requests.
Objašnjenje (HR)
Good example
| 1 | export const getProduct = cache(loadProduct); |
| 2 | // Reuse this function with the same primitive ID within server rendering. |
Explanation (EN)
Sharing one wrapped function supports request-local reuse; persistent caching requires a separate explicit policy.
Objašnjenje (HR)
Notes (EN)
For supported React server rendering, reuse the same cache-wrapped function and equivalent arguments within the request scope; measure framework entry points before assuming they share or split that scope.
Exceptions / Tradeoffs (EN)
Layouts/pages/metadata may share memoized work under the framework. React cache is not a persistent cross-request store, and fresh object arguments can miss because identity differs.