Conversation
…hit rate The Cloudflare cached request rate was ~3.3% due to two issues: 1. cachedFetch used the full request (including per-client headers like Cookie, CF-Connecting-IP, X-Forwarded-For) as the cache key, making every request effectively unique. Now uses a URL-only GET cache key, matching the pattern already used by proxyToR2. 2. Vary: Cookie,Authorization was set on ALL responses including cacheable anonymous ones, fragmenting the cache. Now only set on non-cacheable (authenticated/mutating) responses. Additional improvements: - Only cache GET/HEAD requests (skip POST/PUT/DELETE) - Respect backend Cache-Control (don't cache private/no-store responses) - Only cache 2xx responses - Serve HEAD requests from cached GET responses Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
cachedFetch: The previous implementation used the full request (including per-client headers like Cookie, CF-Connecting-IP, X-Forwarded-For) as the cache key, making every request effectively unique. Now uses a stripped URL-only GET key, matching the pattern already used byproxyToR2.Vary: Cookie, Authorizationon non-cacheable responses: Previously set on ALL responses including cacheable anonymous ones, which fragmented the cache since every unique cookie/auth value created a separate cache entry.Cache-Controldirectives (private/no-store), only cache 2xx responses, serve HEAD from cached GET.Closes #1371
Test plan
deno check lb/main.tspasses🤖 Generated with Claude Code