Skip to content

Switch OpenNext incremental cache from KV to R2#2

Open
jphein wants to merge 4 commits intomasterfrom
claude/switch-caching-kv-to-r2-Y90gb
Open

Switch OpenNext incremental cache from KV to R2#2
jphein wants to merge 4 commits intomasterfrom
claude/switch-caching-kv-to-r2-Y90gb

Conversation

@jphein
Copy link
Copy Markdown
Owner

@jphein jphein commented Apr 20, 2026

KV has per-day operation limits on the Cloudflare free plan; R2 does not,
and includes 10M Class B reads/month free. Swap the incremental cache
override in open-next.config.ts, and replace the kv_namespaces binding
with an r2_buckets binding pointing to the techempower-cache bucket.

Requires the R2 bucket to exist before deploy:
npx wrangler r2 bucket create techempower-cache

https://claude.ai/code/session_01EtZ6fVjJdyAqDR3WbiAqm3

KV has per-day operation limits on the Cloudflare free plan; R2 does not,
and includes 10M Class B reads/month free. Swap the incremental cache
override in open-next.config.ts, and replace the kv_namespaces binding
with an r2_buckets binding pointing to the techempower-cache bucket.

Requires the R2 bucket to exist before deploy:
  npx wrangler r2 bucket create techempower-cache

https://claude.ai/code/session_01EtZ6fVjJdyAqDR3WbiAqm3
Copilot AI review requested due to automatic review settings April 20, 2026 02:42
Copy link
Copy Markdown

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 switches the OpenNext (Cloudflare) incremental cache backend from Cloudflare KV to Cloudflare R2 to avoid KV free-tier operation limits and use an R2 bucket instead.

Changes:

  • Update open-next.config.ts to use the R2 incremental cache override.
  • Update wrangler.jsonc to replace the KV namespace binding with an R2 bucket binding (techempower-cache).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
wrangler.jsonc Replaces kv_namespaces binding with r2_buckets binding for the incremental cache.
open-next.config.ts Switches OpenNext incremental cache override from KV to R2.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread open-next.config.ts
Comment on lines 4 to 6
export default defineCloudflareConfig({
incrementalCache: kvIncrementalCache
incrementalCache: r2IncrementalCache
})
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Addressed in 71399b4.github/workflows/deploy.yml now deploys to Cloudflare Workers via pnpm cf:deploy on push to master/main, using CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID secrets. package.json's deploy script and the hosting section of CLAUDE.md were updated to match.


Generated by Claude Code

Copy link
Copy Markdown

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

Switches the OpenNext incremental cache backend on Cloudflare from KV (operation-limited on free tier) to R2 (more favorable free-tier read limits), updating both the OpenNext config override and Wrangler bindings accordingly.

Changes:

  • Replace OpenNext incremental cache override from KV to R2.
  • Swap Wrangler binding from kv_namespaces to r2_buckets targeting techempower-cache.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
wrangler.jsonc Removes KV namespace binding and adds an R2 bucket binding for the incremental cache.
open-next.config.ts Updates the incremental cache override to use the R2 implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread wrangler.jsonc
Comment on lines +19 to 23
"r2_buckets": [
{
"binding": "NEXT_INC_CACHE_KV",
"id": "77055535c51e442193e5dad69ceb5075"
"binding": "NEXT_INC_CACHE_R2_BUCKET",
"bucket_name": "techempower-cache"
}
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Addressed in 71399b4 — added a JSONC comment on the NEXT_INC_CACHE_R2_BUCKET binding documenting the bucket prereq (npx wrangler r2 bucket create techempower-cache). Skipping preview_bucket_name for now since pnpm cf:preview uses miniflare's local R2 emulator.


Generated by Claude Code

claude added 3 commits April 20, 2026 03:16
- .github/workflows/deploy.yml now runs `pnpm cf:deploy` on push to
  master/main using CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID secrets,
  replacing the Vercel action.
- package.json: `deploy` script points at `opennextjs-cloudflare deploy`;
  the vercel dep was not in devDependencies so nothing to remove there.
- CLAUDE.md: hosting section and commands list now reflect Cloudflare
  Workers + OpenNext as the production target.
- wrangler.jsonc: add JSONC comment documenting the R2 bucket prereq on
  the NEXT_INC_CACHE_R2_BUCKET binding so new environments don't silently
  fail when the bucket is missing.

Note: CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID must be configured
as GitHub Actions repository secrets before the next push to master.

https://claude.ai/code/session_01EtZ6fVjJdyAqDR3WbiAqm3
scripts/deploy.sh reads CLOUDFLARE_API_TOKEN (from the notes field) and
CLOUDFLARE_ACCOUNT_ID (from the custom "id" field) out of the Bitwarden
secure note "techempower cloudflare api", exports them, and runs
pnpm cf:deploy. Requires the vault to be unlocked (BW_SESSION set) and
bw + jq on PATH.

New npm alias "deploy:local" wraps the script so the manual deploy flow
from a dev machine is one command: `pnpm deploy:local`.

CLAUDE.md gets a Deploying section documenting both the GitHub Actions
auto-deploy path and the local Bitwarden-backed path, so Claude running
in this repo knows which secrets live where.

https://claude.ai/code/session_01EtZ6fVjJdyAqDR3WbiAqm3
- Tech Stack table: Vercel -> Cloudflare Workers via OpenNext; add R2
  incremental cache row.
- Useful commands table: drop vercel, add cf:build/cf:preview/cf:deploy
  and deploy:local.
- Deployment section: document the GitHub Actions auto-deploy path
  (required secrets + token scopes), the Bitwarden-backed local deploy
  via `pnpm deploy:local`, and the `techempower-cache` R2 bucket
  prerequisite.
- Environment Variables: split into app-level vs deploy-time tables;
  add CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID.

https://claude.ai/code/session_01EtZ6fVjJdyAqDR3WbiAqm3
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.

3 participants