next.js
40188b5e - [test] Cover `'use cache: private'` in route handlers (#97349)

Commit
12 days ago
[test] Cover `'use cache: private'` in route handlers (#97349) The `use-cache-private` suite covered private caches in server components only, so this adds a route handler that calls one `'use cache: private'` function three times: a concurrent pair, and a third call after a short delay. The concurrent pair joins a single in-flight invocation, while the delayed call lands after the map of pending intra-request invocations has dropped its entry, so it is served from the completed entry that the request retains. Each call passes a fresh object literal, which makes the React `cache()` memo miss on reference equality so that the lookup falls through to the serialized cache key. The cache function also reads a cookie, which covers that request APIs are allowed inside a private cache in a route handler. A second test asserts that nothing is shared across requests. In production private entries are neither persisted nor deduped across requests, so every request re-runs the cache function. In development they are persisted and forced to `revalidate: 0`, so the next request is served the stale entry while a fresh one warms in the background, which the dev branch of the test follows. Both tests pass their own `id` search param, and therefore use their own cache key, so the entry that dev persists for one is never served to the other. This also drops the claim that the directive is not available in route handlers from the `'use cache: private'` reference. Nothing in the source rejects it, and it was already allowed for request work unit stores when that note was written.
Author
Parents
Loading