Skip to content

Cache pages with the bar apart from visitors behind Varnish - #76

Closed
GrimLink wants to merge 3 commits into
mainfrom
vary-page-cache-entry
Closed

GrimLink wants to merge 3 commits into
mainfrom
vary-page-cache-entry

Conversation

@GrimLink

@GrimLink GrimLink commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Makes the bar work behind Varnish, on a live shop and on a developer's own Varnish setup alike, without hurting the visitors' cache.

HttpPlugin now adds siteation_debugbar to Magento's HTTP context on storefront requests that get the bar. That value ends up in the X-Magento-Vary cookie, which both the built in full page cache and Magento's Varnish VCL hash on, so a debugged page gets its own cache entry.

Before this:

  1. A developer holding the key got a Varnish hit (the visitors' page) without a bar on catalog and CMS pages.
  2. A debugged request shared the visitors' hash, and its no-store answer made that entry hit-for-pass for two minutes for everyone.

Scope: frontend only, the admin and APIs have no full page cache to vary. A failure to set the value is logged and the request continues.

Testing Varnish locally: a hit never reaches PHP, so it can never carry a bar, and keyless developer mode gives the bar to every local request (Varnish connects from a private address), so nothing is cached. The new user guide section "Testing Varnish locally" makes the key the switch: the browser holding it gets the bar on its own uncached entry, a private window or curl without it is a visitor that Varnish caches as usual. The vary change is what keeps the two apart.

Notes for review:

  • The vary cookie is set by PHP, so the first request with only the key cookie can still be a Varnish hit. The ?siteation_debugbar_key= redirect, or any pass through page, sets it.
  • HttpPlugin takes HttpContext as a new last constructor argument. Run setup:di:compile after upgrading.
  • Also moves the misplaced X-Magento-Tags docblock in BarInjector onto refuseSharing().

Docs: user guide (new "Testing Varnish locally", troubleshooting points to it), CHANGELOG. Three new HttpPluginTest cases.

@GrimLink
GrimLink requested a review from allrude November 30, 2026 16:00
@GrimLink GrimLink self-assigned this Nov 30, 2026
@GrimLink

GrimLink commented Nov 30, 2026 •

Copy link
Copy Markdown
Member Author

Replaced by #77, a docs only approach.

@GrimLink GrimLink closed this Nov 30, 2026
@GrimLink
GrimLink deleted the vary-page-cache-entry branch November 30, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant