Magento 2 and Varnish Cache
Magento 2 has been in development for several years, through the Merchant Beta release it was announced that there will be out of the box support for Varnish Cache 4. Awesome.
Magento 2 improvements
This is great news on many fronts as modern Magento releases (CE 1.8+ and EE 1.13+) have included a form keys feature that has made HTML caching (and good Magento performance!) harder to implement. The form keys issue is a security feature introduced that makes each HTML page unique and hence cannot be stored in Varnish Cache.
The work around until now has been to use a Magento extension (Such as Nexus Turpentine{:target=”_blank”}) however this can introduce further configuration / complexity to your Magento implementation. Without other options however, this is still the best method to achieve speed / performance improvements in Magento 1.
Magento 2 Varnish Cache design
The sourcecode within the Magento 2 codebase{:target=”_blank”} that relates to Varnish Cache{:target="blank”} uses a similar pattern to the existing Turpentine extension where a custom HTTP header is sent with each page response (The custom header within Magento 2 is called “X-Magento-Tags-Pattern”).
The custom header contains a list of tags that identify features of this HTML page, For example this might be a Category page response that contains an image or pricing for Product ID 123.
If Product ID 123 is then updated, Magento will send a PURGE message to Varnish Cache that any item in its cache that has a HTTP header (X-Magento-Tags-Pattern) with the value of “Product ID 123” needs to be removed from cache. This allows the actual Product page and any associated pages to be cleared from cache when new versions are generated without clearing the cache for all other content. This is good for performance!
Implementing Magento 2 and Varnish Cache
In order to run Varnish Cache on your Magento 2 implementation you need to install Varnish Cache and then deploy a Varnish Cache configuration file (A Varnish Cache VCL file) into your Varnish Cache implementation.
Within Section the process to implement Varnish Cache in front of Magento 2 is to copy paste this code into the Section portal.
If you have any issues / questions about setting up Magento 2 Varnish Cache please touch base through www.Section, You can have a globally distributed Varnish Cache implementation running in seconds, with the features normally missing from a Varnish Cache install - simple access to metrics and logs