cloudflare / cloudflare/vinext
[nextjs-tracker] 'use cache: private' is supported in Route Handlers
- Dominant language
- TypeScript
- Stars
- 8.8k
- Forks
- 406
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 120
Description
## Next.js change
Next.js confirmed and documented that the `'use cache: private'` directive **is** available in Route Handlers. The docs previously claimed "This directive is not available in Route Handlers" — that note was removed, and new test coverage exercises a `'use cache: private'` function called from a route handler (concurrent + delayed calls, reading cookies inside the private cache, verifying no cross-request sharing in prod and stale-while-revalidate persistence in dev).
**Commits:** [40188b5](https://github.com/vercel/next.js/commit/40188b5e392dbbba87fa86a76e783e27f39a8475)
**Next.js files changed:** `docs/01-app/03-api-reference/01-directives/use-cache-private.mdx`, `test/e2e/app-dir/use-cache-private/app/route-handler/route.ts`, `test/e2e/app-dir/use-cache-private/use-cache-private.test.ts`
## Why this matters to vinext
vinext reimplements the `"use cache"` family and request-scoped caching (`packages/vinext/src/shims/cache.ts`, `packages/vinext/src/server/isr-cache.ts`, `packages/vinext/src/server/fetch-cache.ts`, and App Router route-handler dispatch in `packages/vinext/src/entries/app-rsc-entry.ts` / `server/app-*.ts`). If vinext currently rejects or silently no-ops `'use cache: private'` inside route handlers, it diverges from Next.js. The documented semantics to match: request APIs (cookies/headers) are allowed inside a private cache in a route handler; in prod private entries are neither persisted nor deduped across requests (re-run every request); intra-request concurrent calls join a single in-flight invocation and a later same-request call is served from the completed entry.
## Priority
**Important**
## Suggested action
- Investigate: verify whether `'use cache: private'` works in vinext route handlers today. If not supported, implement it in the cache runtime and route-handler dispatch. Port the Next.js route-handler test (concurrent pair joins one invocation, delayed call served from completed entry, cookie read inside private cache, no cross-request sharing in prod). Relates to existing private-cache issues #1937 (dev persistence) and #2820 (intra-request entry reuse) but is specifically about route-handler availability.
Contributor guide
Research direction
Inspect packages/vinext/src/shims/cache.ts, packages/vinext/src/server/isr-cache.ts, packages/vinext/src/server/fetch-cache.ts, and route-handler dispatch in packages/vinext/src/entries/app-rsc-entry.ts and server/app-*.ts. Compare current behavior with the Next.js route-handler test and the stated private-cache semantics. Done means route handlers allow request APIs in private caches, reuse concurrent and later calls within a request, and avoid cross-request persistence in production.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100