mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #646] [MERGED] feat: implement cacheForRequest() per-request factory cache #743
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#743
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/646
Author: @JamesbbBriz
Created: 3/22/2026
Status: ✅ Merged
Merged: 3/28/2026
Merged by: @james-elicx
Base:
main← Head:feat/cache-for-request📝 Commits (3)
e781265feat: add cacheForRequest() — per-request factory cacheeb667a9fix: address review feedback for cacheForRequest01a76b1fix: add void operator to suppress no-floating-promises lint warnings📊 Changes
7 files changed (+224 additions, -3 deletions)
View changed files
📝
packages/vinext/package.json(+4 -0)➕
packages/vinext/src/cache.ts(+11 -0)📝
packages/vinext/src/index.ts(+1 -0)➕
packages/vinext/src/shims/cache-for-request.ts(+89 -0)📝
packages/vinext/src/shims/unified-request-context.ts(+10 -3)➕
tests/cache-for-request.test.ts(+108 -0)📝
tests/unified-request-context.test.ts(+1 -0)📄 Description
Summary
Implements
cacheForRequest()from RFC #623 — a per-request factory cache that lazily initializes values on first call and returns the cached result for subsequent calls within the same request.API
Key design decisions:
await getDb()share one invocation)Changes
shims/cache-for-request.tscacheForRequest()implementation (17 lines of logic)shims/unified-request-context.tsrequestCache: WeakMap<Function, unknown>field + shallow-clone comment syncpackage.json"./cache-for-request"exportBlast radius
Zero. New file + one new field with
new WeakMap()default (~0.1μs per request). No existing behavior changes.Test plan
Tested with Prisma v7 + Hyperdrive on Workers. Happy to add unit tests — let me know the preferred test file location.
Addresses #623 · Relates to #537
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.