Replace Vercel KV adapter with Vercel Runtime Cache API#2475
Replace Vercel KV adapter with Vercel Runtime Cache API#2475bookernath merged 1 commit intocanaryfrom
Conversation
🦋 Changeset detectedLatest commit: d151188 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
84db95e to
2268e2d
Compare
2268e2d to
fd474b6
Compare
2244339 to
520e452
Compare
520e452 to
10bf95a
Compare
10bf95a to
f6b62bd
Compare
f6b62bd to
cf469dc
Compare
cf469dc to
9f357fa
Compare
9f357fa to
ae08fd6
Compare
0785523 to
f78136d
Compare
|
Just noting that we should probably wait for either for Vercel edge runtime support for this or for CF support for nodejs runtime. |
8ad5268 to
204e0be
Compare
0a1660e to
c66dec2
Compare
c66dec2 to
6bc63bc
Compare
6bc63bc to
6b1e018
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR replaces the Vercel KV adapter with Vercel Runtime Cache API to improve caching performance. The change removes both Vercel KV and BC KV adapters in favor of a new runtime cache implementation that provides better cold-load performance.
- Implements new RuntimeCacheAdapter using Vercel's Runtime Cache API
- Removes deprecated Vercel KV and BC KV adapters and their dependencies
- Updates adapter selection logic to prioritize Runtime Cache for Vercel environments
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| core/package.json | Updates dependencies, replacing @vercel/kv with @vercel/functions and adding urlpattern-polyfill |
| core/lib/kv/index.ts | Replaces KV adapter selection logic to prioritize Runtime Cache for Vercel environments |
| core/lib/kv/adapters/vercel.ts | Removes deprecated Vercel KV adapter implementation |
| core/lib/kv/adapters/vercel-runtime-cache.ts | Adds new RuntimeCacheAdapter using Vercel Runtime Cache API |
| core/lib/kv/adapters/upstash.ts | Removes memory caching layer from Upstash adapter |
| core/lib/kv/adapters/bc.ts | Removes deprecated BC KV adapter implementation |
| .changeset/chatty-forks-sniff.md | Adds changeset entry for the runtime cache implementation |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
| return values as Array<Data | null>; |
There was a problem hiding this comment.
The type assertion as Array<Data | null> bypasses TypeScript's type checking. Consider using a type guard or proper typing to ensure type safety instead of disabling the linting rule.
| // eslint-disable-next-line @typescript-eslint/consistent-type-assertions | |
| return values as Array<Data | null>; | |
| // Return values directly, as they are Array<Data | null> | |
| return values; |
6b1e018 to
30caa5f
Compare
30caa5f to
d151188
Compare
migueloller
left a comment
There was a problem hiding this comment.
LGTM 👍🏻
Just had a couple of questions.
| "lru-cache": "^11.1.0", | ||
| "lucide-react": "^0.474.0", | ||
| "next": "15.4.2-canary.10", | ||
| "next": "15.5.1-canary.4", |
There was a problem hiding this comment.
Was upgrading Next.js required to leverage the new Runtime Cache?
There was a problem hiding this comment.
No, this was initially desirable when I thought we would move to Node.js middleware as part of this change, so I wanted to be on a version where that feature was considered "stable". Upon review I probably should have decoupled the version bump from this PR once it was clear it was not necessary.
There was a problem hiding this comment.
Yeah, I would suggested we do that if we hadn't merged already. Thanks for the explanation 🙏🏻
|
|
||
| import { MemoryKvAdapter } from './memory'; | ||
|
|
||
| const memoryKv = new MemoryKvAdapter(); |
There was a problem hiding this comment.
How come we removed the memory adapter from the Upstash adapter? This seems unrelated to adding Runtime Cache.
Also, should we have deleted the ./memory.ts file as well?
There was a problem hiding this comment.
Memory KV is now handled centrally outside of the individual adapters in the kv/index.ts.
| ); | ||
|
|
||
| // Return null for all keys if Runtime Cache is unavailable | ||
| return keys.map(() => null); |
There was a problem hiding this comment.
Is the idea here that returning null behaves as if the cache entries don't exist?
There was a problem hiding this comment.
Yes, I want the application to treat this as a cache miss and gracefully continue to load the page even if the cache is degraded. Memory KV will still provide some offload in most scenarios.
What/Why?
Implement Vercel Runtime Cache API as replacement for Vercel KV
Remove Vercel KV and BC KV adapters as they are no longer needed.
As a next step, we could refactor the KV adapters to look more like simple fetch cache adapters, as the only purpose of these adapters is to cache a fetch in middleware.
Testing
After loading up a session in the US for a US-hosted storefront, I did a cold load from Sydney:
https://www.webpagetest.org/result/250822_YiDcYY_8GH/
This cold-load performance shows that Runtime Cache is working well.
Migration