Varnish Magento2 Configuration¶
- Install Varnish on the server
- Acquire a Magento VCL file using
- Store the VCL file in
- Enable use of Varnish cache in Admin > Stores > Configuration > System > Full Page Cache > Caching Application
update core_config_data set value = 2 where path = "system/full_page_cache/caching_application"
- Check the Varnish Configuration section's connection details
- Check HTTP headers for
Large Header size issues can be potentially solved looking here
Increasing the workspace size can cause varnish to run out of memory. This can be confirmed by running the following
varnishlog | grep abandoned
If you see the following, then varnish has panicked.
- The workspace needs to be big enough for the largest category to fit comfortably within it
- Customise Magento to make the headers smaller
Checking if a customer is logged in¶
When the full page cache is enabled, Magento 2 makes it impossible to check certain things in the customer session.
This is done in
\Magento\PageCache\Model\Layout\DepersonalizePlugin::afterGenerateXml and happens immediately after layout
generation is completed.
If you need to know if a customer is logged in or not but do not need any private identifiable information you can
check this using the following the HTTP context class
1 2 3 4
/** @var \Magento\Framework\App\Http\Context */ $context = $this->context; $isLoggedIn = $this->context->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
This will return a boolean value.