feat(runtime): switch page cache to opt-in via PAGE_CACHE_ALLOWED_KEY - #1200
Conversation
Replaces the opt-out model (cache unless PAGE_DIRTY_KEY is set) with an opt-in model (cache only if PAGE_CACHE_ALLOWED_KEY is set). Apps that do not explicitly opt in will no longer receive CDN Cache-Control headers from the runtime, preserving their existing behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tagging OptionsShould a new tag be published when this PR is merged?
|
📝 WalkthroughWalkthroughThe PR refactors page cache eligibility logic in middleware from using a ChangesPage Cache Eligibility Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
DECO_PAGE_CACHE_ENABLEDenv var — CDN caching no longer needs to be explicitly enabled via environment variableCache-ControlwhenPAGE_CACHE_ALLOWED_KEYis present in the bagPAGE_DIRTY_KEYimport/usage from the runtime middlewarePAGE_CACHE_ALLOWED_KEYwas already defined inblocks/utils.tsxand exported fromblocks/mod.ts; this PR wires it into the runtimeContext
Previously, the runtime applied
Cache-Control: public, max-age=90...to all HTML responses whenDECO_PAGE_CACHE_ENABLED=true, relying on apps to setPAGE_DIRTY_KEYto opt out. This had two problems:The new model requires apps to explicitly set
PAGE_CACHE_ALLOWED_KEYin the bag to receive CDN cache headers. No env var needed. Apps that don't set the key are unaffected (their existing proxy/CDN behavior is preserved).Test plan
PAGE_CACHE_ALLOWED_KEYset by vtex middleware → runtime appliesCache-Control: public, max-age=90, s-maxage=90, stale-while-revalidate=3600, stale-if-error=86400Set-Cookie→ alwaysno-storeregardless of key (existing behavior preserved)DECO_PAGE_CACHE_ENABLED=truein env → cache works normally (env var no longer required)🤖 Generated with Claude Code