Skip to content

Replace Vercel KV adapter with Vercel Runtime Cache API#2475

Merged
bookernath merged 1 commit intocanaryfrom
runtime-cache-3
Aug 23, 2025
Merged

Replace Vercel KV adapter with Vercel Runtime Cache API#2475
bookernath merged 1 commit intocanaryfrom
runtime-cache-3

Conversation

@bookernath
Copy link
Copy Markdown
Contributor

@bookernath bookernath commented Jul 10, 2025

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

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jul 10, 2025

🦋 Changeset detected

Latest commit: d151188

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@bigcommerce/catalyst-core Minor

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

@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
catalyst-b2b Ready Ready Preview Comment Aug 23, 2025 3:45pm
catalyst-canary Ready Ready Preview Comment Aug 23, 2025 3:45pm
3 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
catalyst Ignored Ignored Aug 23, 2025 3:45pm
catalyst-au Ignored Ignored Preview Aug 23, 2025 3:45pm
catalyst-uk Ignored Ignored Preview Aug 23, 2025 3:45pm

This comment was marked as outdated.

@bookernath bookernath force-pushed the runtime-cache-3 branch 4 times, most recently from 2244339 to 520e452 Compare July 14, 2025 14:48
@chanceaclark
Copy link
Copy Markdown
Contributor

Just noting that we should probably wait for either for Vercel edge runtime support for this or for CF support for nodejs runtime.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +39 to +40
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
return values as Array<Data | null>;
Copy link

Copilot AI Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// 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;

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@migueloller migueloller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻

Just had a couple of questions.

Comment thread core/package.json
"lru-cache": "^11.1.0",
"lucide-react": "^0.474.0",
"next": "15.4.2-canary.10",
"next": "15.5.1-canary.4",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was upgrading Next.js required to leverage the new Runtime Cache?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea here that returning null behaves as if the cache entries don't exist?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants