How to configure Varnish for the warmer
The extension works with Varnish without any changes when you use the VCL file generated by Magento (Stores -> Configuration -> Advanced -> System -> Full Page Cache -> Varnish Configuration, the Export VCL button). Of all cookies, this VCL takes only X-Magento-Vary into account, so the other cookies the warmer sends do not affect caching.
If your VCL was customized by you or your hosting provider, and it skips the cache (return (pass)) for requests with unknown cookies or adds the Cookie header to the cache key, you need to remove the warmer's cookies in vcl_recv.
Cookies used by the warmer
| Cookie | Purpose |
|---|---|
CacheWarmer | tells Magento which page variation (for example, customer group and currency) to render for a warming request |
CacheWarmerStatus | marks the request that checks if a page is already in the cache |
mst-cache-warmer-track | used for the cache hit statistics |
mst-cache-warmer-toolbar | shows the debug toolbar on the storefront |
Why the status cookie matters
To check if a page is cached, the extension requests it with the CacheWarmerStatus cookie. If Varnish returns the page from the cache, the page gets the Cached status. If the request reaches Magento instead, Magento does not render the page and returns only *, and the page gets the Pending status.
When your VCL skips the cache for requests with this cookie, every check reaches Magento. As a result, all pages are shown as Pending, even though Varnish has them in the cache, and the warmer requests the same pages again and again.
VCL configuration
Add these lines to the beginning of sub vcl_recv in your VCL, before any rule that checks cookies:
sub vcl_recv {
# Mirasvit Page Cache Warmer: remove the warmer cookies before the cache lookup
if (req.http.Cookie) {
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)CacheWarmer=[^;]*", "");
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)CacheWarmerStatus=[^;]*", "");
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)mst-cache-warmer-track=[^;]*", "");
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)mst-cache-warmer-toolbar=[^;]*", "");
set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
if (req.http.Cookie ~ "^\s*$") {
unset req.http.Cookie;
}
}
# ... the rest of your vcl_recv
}
Remove all four cookies. If you remove only CacheWarmer, mst-cache-warmer-track, and mst-cache-warmer-toolbar, the status check still skips the cache, and pages stay Pending.
After you change the VCL, reload Varnish and run bin/magento mirasvit:cache-warmer --status to update the page statuses.
The CacheWarmer cookie is how the warmer asks Magento for a page variation of a specific customer group or currency. If you warm pages for logged-in customer groups or several currencies, check after the change that these variations are cached with the correct prices.