Magento not hitting Varnish cache

Magento not hitting Varnish cache

August 2, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento not hitting Varnish cache

Why Your Magento Installation Isn’t Hitting Varnish Cache

Setting up an e-commerce platform like Magento with Nginx and Varnish cache can significantly improve your website’s performance. However, when the cache isn’t hit as expected, it can be frustrating to troubleshoot. Let’s dive into why you might not be seeing hits on your Varnish cache.

Understanding the Problem

The key issue lies in the cookies being set and passed along with the request. In your provided HTTP header output, you can see several Set-Cookie lines, including frontend, currency, and others prefixed with PAGECACHE_ENV. These cookies are preventing Varnish from caching your Magento pages effectively.

The Role of Cookies in Caching

Cookies play a crucial role in maintaining session state for users. However, they also act as a barrier to efficient caching. When a request contains cookies that vary between user sessions, the cache server cannot serve cached content because it can’t guarantee the response will be identical across all requests.

Why Varnish Isn’t Removing Cookies

The default VCL (Varnish Configuration Language) file provided by your pagecache module should handle this. It typically includes a sub vcl_hit section that removes cookies before serving cached content:

sub vcl_hit {
    remove beresp.http.set-cookie;
}

However, there are a few scenarios where Varnish might not be applying this rule as expected:

  1. Incorrect VCL Application: Ensure your configured Varnish server is using the correct VCL file. Double-check that you’ve properly linked the .vcl file in your Varnish configuration.

  2. Cache Bypass Settings: Look at your default.vcl file to ensure it’s not bypassing caching for specific requests due to certain conditions like request headers or URL patterns.

  3. Magento Configuration Issues: The pagecache module might not be configured correctly, leading to the cookies being set unnecessarily or in a way that Varnish can’t handle effectively.

Solutions to Improve Cache Hits

  1. Review Your Default.vcl File: Double-check your default.vcl file for any misconfigurations or inconsistencies with the expected behavior. Ensure it includes the remove beresp.http.set-cookie; line in the appropriate section.

  2. Optimize Magento Cookies: Work on reducing the number of cookies set by Magento, especially if they are not necessary for your use case. You can do this through Magento’s configuration or by using third-party extensions to optimize cookie usage.

  3. Check Your Varnish Configuration: Ensure that your Varnish server is correctly configured and linked with the appropriate VCL file. Double-check that it’s running on the expected port (usually 80) and handling requests as intended.

Conclusion

In most cases, the issue of missing cache hits in a Magento-Varnish setup stems from misconfigurations or inconsistencies in the Varnish Configuration Language file. Always ensure you’re using the latest version of the pagecache module and double-check your VCL files for any discrepancies.

Remember that efficient caching requires a careful balance between performance optimization and maintaining user session state. If you find the issue persists, consider consulting with a Magento or Varnish expert to troubleshoot more complex configuration issues.

For further reading on optimizing Magento performance using Varnish, check out our comprehensive guide at Laravel Company’s Blog for in-depth insights and best practices.

Cache Performance Extensions Configuration

Our network