Repository navigation
feat: edge-cache POST _serverFn responses - #70
Merged
Merged
Conversation
Non-cacheable responses (POST _serverFn, bypass paths) were leaving Cache-Control empty after removing the blanket no-cache. Now applies the profile cache headers so responses are explicit about cacheability. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Server function POST requests (/_serverFn/, /_server/) carry public CMS section data (shelves, deferred sections) that benefits from edge caching. Since POST responses can't use standard HTTP caching, we hash the request body with SHA-256 and use it as a synthetic GET cache key in the Cloudflare Cache API. Includes full SWR + SIE support (stale-while-revalidate with background refresh, stale-if-error fallback) matching the existing GET cache flow. Responses with Set-Cookie are never cached to prevent session leaking. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
1 issue found across 1 file
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="src/sdk/workerEntry.ts">
<violation number="1" location="src/sdk/workerEntry.ts:915">
P2: Missing `toStore.headers.delete("CDN-Cache-Control")` in the SWR background revalidation store path. Both the MISS path (below) and the existing `storeInCache` helper delete this header before putting into the Cache API. Without it, a `CDN-Cache-Control` header from the origin response leaks into the cached entry during background refresh.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Without segment info in the cache key, users in different regions or sales channels would share cached responses — leaking regional prices. Now mirrors the GET cache key logic: includes buildSegment (device, salesChannel, regionId, flags) and CF geo data. Logged-in users bypass the cache entirely to prevent personalized content leaking. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Matches the MISS path and existing storeInCache helper which both delete this header before cache.put(). Without it, a CDN-Cache-Control header from the origin response leaks into the cached entry. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
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="src/sdk/workerEntry.ts">
<violation number="1" location="src/sdk/workerEntry.ts:862">
P2: Redundant `buildSegment(request)` call — this user-provided callback is invoked twice for every non-logged-in POST request. Hoist the segment result above the body-read so both the logged-in check and cache-key builder share it.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
buildSegment(request) was called twice per non-logged-in POST request. Hoist result into sfnSegment, reuse for both logged-in check and cache key. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Deferred section data (shelves, product lists) is public and read-only. Using GET allows standard HTTP caching at edge and browser level. Typical payload is ~3KB, well within Cloudflare Workers 16KB URL limit. TanStack Start serializes the input into the URL automatically via TSS. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
🎉 This PR is included in version 1.3.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This was referenced Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #69 (merged before these commits landed).
Flow
Test plan
Summary by cubic
Edge-cache POST
_serverFn/_serverresponses using a body-hash key, and switch deferred section loads to GET to leverage standard HTTP caching. Also apply profile cache headers on non-cacheable responses and strip CDN directives when storing refreshed entries.New Features
Set-Cookie.loadDeferredSectionnow uses GET so responses cache at the edge and in browsers; payload is serialized into the URL (~3–4KB, within Cloudflare Workers’ limit).X-CacheandX-Cache-Profile; shelf hits drop from ~1s to <10ms.Bug Fixes
buildSegmentto avoid duplicate calls.CDN-Cache-Controlbefore caching during SWR background refresh to avoid storing origin CDN directives.Written for commit 1eae7e4. Summary will update on new commits.