Enhance cacheability check in isRequestCacheable method#25
Merged
mage-os-ci merged 1 commit intomainfrom Apr 19, 2026
Merged
Conversation
Contributor
Author
|
@GrimLink FYI I think this same issue affects Hyva's implementation. |
Member
|
If I follow correctly, this only happens due to the PHP code change. However, Hyvä recommends to just change the VCL in their docs. So I don't think this is an issue in Hyvä. |
Member
|
Good catch, by the way :) |
Contributor
Author
Varnish is a separate matter--this only affects Magento's native FPC. |
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.
Problem
The BFCache optimization in
module-theme-optimizationremovesno-storefromCache-Controlheaders to enable browser back/forward cache. However, for Magento's native FPC (non-Varnish/Fastly), this only works for FPC cache misses, not hits.Root Cause
The BFCache plugin intercepts
setNoCacheHeaders()and checks for thepublic.*s-maxagepattern to identify cacheable pages:This works on MISS because the response has
Cache-Control: public, s-maxage=Xbefore processing.On HIT, the response is loaded from cache with already-processed headers:
Cache-Control: max-age=0, must-revalidate, no-cache— nopublicors-maxageto match.The Trigger
HttpPlugin::beforeSendResponse()callssetNoCacheHeaders()when the HTTP context vary string doesn't match the vary cookie:On FPC HITs, this mismatch frequently occurs because
Kernel::buildResponse()creates a new context from cached data but doesn't propagate it to the sharedContextsingleton thatHttpPluginchecks.Result
FPC HITs receive
no-storein the response, defeating the BFCache optimization for the most common case (cached pages).Solution
Extend the BFCache plugin's pattern detection to recognize FPC HIT responses.
FPC HITs have
Cache-Controlwith:public(stripped during original processing)private(never set for cacheable pages)no-store(stripped by BFCache on original MISS)A more proper solution might involve fixing the core HttpPlugin Context, but this is a far less invasive way to achieve the same result.