Repository navigation
feat(worker): regionalized cache segmentation and purge support - #15
Conversation
- Add regionId to SegmentKey for per-region cache differentiation - Include regionId in hashSegment cache key computation - Refactor handlePurge to accept salesChannels and regionIds in request body, generating all segment permutations for thorough cache invalidation - Include __v (build hash) in purge cache keys for correctness - Update edge caching and route config skill docs Made-with: Cursor
|
🎉 This PR is included in version 0.24.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
There was a problem hiding this comment.
4 issues found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name=".cursor/skills/deco-cms-route-config/SKILL.md">
<violation number="1" location=".cursor/skills/deco-cms-route-config/SKILL.md:45">
P2: Re-add `NotFoundPage` to the example import; the updated snippet still references it and will not compile as written.</violation>
</file>
<file name="src/sdk/workerEntry.ts">
<violation number="1" location="src/sdk/workerEntry.ts:468">
P1: `buildPurgeSegments` misses `device + regionId` cache keys when `salesChannel` is absent, so region-only segmented entries are not purged.</violation>
</file>
<file name=".cursor/skills/deco-edge-caching/SKILL.md">
<violation number="1" location=".cursor/skills/deco-edge-caching/SKILL.md:191">
P2: This deploy example does not actually bind `BUILD_HASH` into the Worker runtime, so `env.BUILD_HASH` will be empty and cache versioning will silently do nothing.</violation>
<violation number="2" location=".cursor/skills/deco-edge-caching/SKILL.md:292">
P2: `unknown` cache status is not equivalent to a HIT. The Worker also serves MISS/BYPASS responses, so this guidance can cause teams to overestimate cache hit rate.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| const channels = body.salesChannels ?? ["1"]; | ||
| const regions: Array<string | undefined> = [undefined, ...(body.regionIds ?? [])]; | ||
|
|
||
| const segments: SegmentKey[] = []; | ||
| for (const device of devices) { | ||
| for (const salesChannel of channels) { | ||
| for (const regionId of regions) { | ||
| segments.push({ device, salesChannel, regionId }); | ||
| } | ||
| } | ||
| segments.push({ device }); | ||
| } |
There was a problem hiding this comment.
P1: buildPurgeSegments misses device + regionId cache keys when salesChannel is absent, so region-only segmented entries are not purged.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/sdk/workerEntry.ts, line 468:
<comment>`buildPurgeSegments` misses `device + regionId` cache keys when `salesChannel` is absent, so region-only segmented entries are not purged.</comment>
<file context>
@@ -442,6 +454,32 @@ export function createDecoWorkerEntry(
+
+ function buildPurgeSegments(body: PurgeRequestBody): SegmentKey[] {
+ const devices: Array<"mobile" | "desktop"> = ["mobile", "desktop"];
+ const channels = body.salesChannels ?? ["1"];
+ const regions: Array<string | undefined> = [undefined, ...(body.regionIds ?? [])];
+
</file context>
| const channels = body.salesChannels ?? ["1"]; | |
| const regions: Array<string | undefined> = [undefined, ...(body.regionIds ?? [])]; | |
| const segments: SegmentKey[] = []; | |
| for (const device of devices) { | |
| for (const salesChannel of channels) { | |
| for (const regionId of regions) { | |
| segments.push({ device, salesChannel, regionId }); | |
| } | |
| } | |
| segments.push({ device }); | |
| } | |
| const channels: Array<string | undefined> = [undefined, ...(body.salesChannels ?? ["1"])]; | |
| const regions: Array<string | undefined> = [undefined, ...(body.regionIds ?? [])]; | |
| const segments: SegmentKey[] = []; | |
| for (const device of devices) { | |
| segments.push({ device }); | |
| for (const salesChannel of channels) { | |
| for (const regionId of regions) { | |
| if (salesChannel === undefined && regionId === undefined) continue; | |
| segments.push({ device, salesChannel, regionId }); | |
| } | |
| } | |
| } |
| import { createFileRoute, notFound } from "@tanstack/react-router"; | ||
| import { cmsRouteConfig, NotFoundPage } from "@decocms/start/routes"; | ||
| import { createFileRoute } from "@tanstack/react-router"; | ||
| import { cmsRouteConfig, loadDeferredSection } from "@decocms/start/routes"; |
There was a problem hiding this comment.
P2: Re-add NotFoundPage to the example import; the updated snippet still references it and will not compile as written.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .cursor/skills/deco-cms-route-config/SKILL.md, line 45:
<comment>Re-add `NotFoundPage` to the example import; the updated snippet still references it and will not compile as written.</comment>
<file context>
@@ -41,41 +41,72 @@ The catch-all route handles all CMS-managed pages (PDP, PLP, institutional pages
-import { createFileRoute, notFound } from "@tanstack/react-router";
-import { cmsRouteConfig, NotFoundPage } from "@decocms/start/routes";
+import { createFileRoute } from "@tanstack/react-router";
+import { cmsRouteConfig, loadDeferredSection } from "@decocms/start/routes";
import { DecoPageRenderer } from "@decocms/start/hooks";
+import type { ResolvedSection, DeferredSection } from "@decocms/start/cms";
</file context>
| import { cmsRouteConfig, loadDeferredSection } from "@decocms/start/routes"; | |
| import { cmsRouteConfig, loadDeferredSection, NotFoundPage } from "@decocms/start/routes"; |
| When migrating to TanStack Workers, compare cache metrics: | ||
| - Production (Deno/Fresh on Kubernetes) typically shows high HIT rates because traffic volume keeps caches warm | ||
| - Staging Workers may show lower HIT rates due to lower traffic, plus "unknown" status from internal Cache API | ||
| - The "unknown" requests on Workers are functionally equivalent to HITs — they're served from the Worker's Cache API without hitting the origin server function |
There was a problem hiding this comment.
P2: unknown cache status is not equivalent to a HIT. The Worker also serves MISS/BYPASS responses, so this guidance can cause teams to overestimate cache hit rate.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .cursor/skills/deco-edge-caching/SKILL.md, line 292:
<comment>`unknown` cache status is not equivalent to a HIT. The Worker also serves MISS/BYPASS responses, so this guidance can cause teams to overestimate cache hit rate.</comment>
<file context>
@@ -181,13 +181,125 @@ const cachedPLP = createCachedLoader("vtex/plp", vtexPLP, {
+When migrating to TanStack Workers, compare cache metrics:
+- Production (Deno/Fresh on Kubernetes) typically shows high HIT rates because traffic volume keeps caches warm
+- Staging Workers may show lower HIT rates due to lower traffic, plus "unknown" status from internal Cache API
+- The "unknown" requests on Workers are functionally equivalent to HITs — they're served from the Worker's Cache API without hitting the origin server function
+
## Key Constraints
</file context>
| run: npx wrangler deploy | ||
| env: | ||
| BUILD_HASH: ${{ github.sha }} |
There was a problem hiding this comment.
P2: This deploy example does not actually bind BUILD_HASH into the Worker runtime, so env.BUILD_HASH will be empty and cache versioning will silently do nothing.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .cursor/skills/deco-edge-caching/SKILL.md, line 191:
<comment>This deploy example does not actually bind `BUILD_HASH` into the Worker runtime, so `env.BUILD_HASH` will be empty and cache versioning will silently do nothing.</comment>
<file context>
@@ -181,13 +181,125 @@ const cachedPLP = createCachedLoader("vtex/plp", vtexPLP, {
+```yaml
+# .github/workflows/deploy.yml
+- name: Deploy to Cloudflare Workers
+ run: npx wrangler deploy
+ env:
+ BUILD_HASH: ${{ github.sha }}
</file context>
| run: npx wrangler deploy | |
| env: | |
| BUILD_HASH: ${{ github.sha }} | |
| run: npx wrangler deploy --var BUILD_HASH:${GITHUB_SHA} |
…anStack Start, esbuild) (#832) Closes the open Dependabot alerts in one PR, with the lockfile. The Dependabot PRs (#811, #828, #747) only touch `package.json`, so they all fail `bun install --frozen-lockfile` in CI. | Package | From | To | Alerts | |---|---|---|---| | `react-server-dom-webpack` (tanstack-rsc-smoke) | 19.2.7 | 19.2.9 | #19, critical: RSC RCE, GHSA-xqc2-xf4c-x3h3 | | `react` / `react-dom` (all pinned workspaces) | 19.2.7 | 19.2.9 | peer floor of the above | | `next` (nextjs, compat-v7, nextjs-binding-smoke) | 16.3.8 | 16.4.6 | #10–12, #14, #15, #17, #18, #20–22 | | `@tanstack/react-start` (tanstack, compat-v7, smokes) | 1.168.58 | 1.168.61 | #2–4, #7, #9 | | `@tanstack/react-router` | 1.170.39 | 1.170.42 | the version react-start 1.168.61 pins, so it stays a single copy | | `esbuild` (blocks, tanstack, compat-v7) | ^0.27.3 | ^0.28.2 | #5, #6, #8 (low) | `bun.lock` was regenerated with bun 1.3.5 (the `packageManager`). React dedupes to a single 19.2.9 at the root, with no nested copies. Vite still has its own transitive `[email protected]` (its own range); that is outside our manifests. Supersedes #811, #828 and #747. ### Verified locally (bun 1.3.5, node 24) - `bun install --frozen-lockfile` ✅ - `bun run typecheck` ✅ · `bun run lint` ✅ - `bun x vitest run`: 3388 passed, 0 failed ✅ (includes `tests/release.test.ts`) - `examples/tanstack-worker-smoke`: build + smoke ✅ - `examples/nextjs-binding-smoke`: build + smoke ✅ - `examples/tanstack-rsc-smoke`: build + typecheck ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Bumps several dependencies to clear open Dependabot security alerts, including a critical RCE in `react-server-dom-webpack` (GHSA-xqc2-xf4c-x3h3). The lockfile was regenerated so `bun install --frozen-lockfile` passes — React dedupes to a single 19.2.9 copy. **Dependencies** - `react`, `react-dom`, and `react-server-dom-webpack` 19.2.7 → 19.2.9 - `next` 16.3.8 → 16.4.6 - `@tanstack/react-start` 1.168.58 → 1.168.61, with `@tanstack/react-router` 1.170.42 - `esbuild` ^0.27.3 → ^0.28.2; Vite's own transitive `[email protected]` is untouched - Typecheck, lint, the full test suite (3388 passed), and the Next.js and TanStack smoke builds all pass <sup>Written for commit 123acc8. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/decocms/blocks/pull/832?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/decocms/blocks/832?returnTo=https%3A%2F%2Fgithub.com%2Fdecocms%2Fblocks%2Fpull%2F832&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. --> Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
regionIdtoSegmentKeyfor per-region edge cache differentiationregionIdinhashSegmentcache key computationhandlePurgeto acceptsalesChannelsandregionIdsin request body, generating all segment permutations for thorough cache invalidation__v(build hash) in purge cache keys for correctnessContext
Part of the VTEX regionalization support. Sites that use postal-code-based regionalization (e.g. Casa&Video) need the edge cache to be segmented per
regionId, and the purge endpoint must be able to target those region-specific entries.The
regionIdfield is optional onSegmentKey— sites without regionalization simply omit it and get the same behavior as before.Test plan
tsc --noEmitpasses (confirmed locally)buildSegmentreturningregionIdand verify cache keys includer=<regionId>/_cache/purgewithregionIdsin body and verify region-specific entries are purgedMade with Cursor
Summary by cubic
Add per-region edge cache keys and purge support to handle VTEX regionalization. Sites can now cache and invalidate content by
regionIdwithout impacting non-regionalized setups.New Features
regionIdtoSegmentKeyand included it inhashSegmentto create region-scoped cache entries.salesChannelsandregionIds, generates all segment permutations, and includes__v(build hash) in purge keys.X-CacheandX-Cache-Reasonheaders;private,none, andcartprofiles always bypass cache.BUILD_HASH), and route cache defaults.Migration
regionIdfrombuildSegment; omit it otherwise./_cache/purge, passregionIds(andsalesChannelsif needed) to invalidate region-specific entries.BUILD_HASHin deploys so versioned cache keys are generated.Written for commit 109d067. Summary will update on new commits.