By default Magento caches the pages that are accessed by the user. The pages are cached in different versions corresponding to the customer group, if the customer is logged in, which store view and currency is configured. Based on these attribute values the value for the X-Magento-Vary cookies is being generated and this helps to identify which of the cached versions of the specific page should be used.

We would like to pre-cache all instances for all pages, but do not know how to access all pages for all of the above mentioned combination.

However, to keep things simple, lets assume we only want to pre-cache all pages for all customer groups and if a customer is logged in. Through PHP's file_get_contents() function we are able to pre-cache all pages,but only for never logged in users / users that have no cookies, yet.

Does someone know if it is possible to load the page for a specific combination of customer_group and customer_logged_in attributes? If it is possible, we assume that we have to provide the data for context parameter of the file_get_contents() function. Has someone an idea what data we have to provide? We already tried to manually set the X-Magento-Vary cookie with a value for a specific combination but this is not the trick.

We appreciate any help! :)

1 Answer 1


We have open sourced our cache priming tool for Magento 2. https://github.com/8WireDigital/magento2-module-primer, I believe it might achieve what you're after.

To build a database of requests to prime we log request information along with contents of the X-Magento-Vary cookie, this is necessary so we can differentiate between customer groups etc. We then use Guzzle to re-request the urls after cache flushes, therefore priming the request in varnish. To handle X-Magento-Vary we parse a cookie with the HTTP request containing the X-Magento-Vary contents.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.