Magento - serve cached content from Varnish while requesting a new object from the backend

Magento - serve cached content from Varnish while requesting a new object from the backend

August 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - serve cached content from Varnish while requesting a new object from the backend

Understanding Varnish Cache and its Role in Magento Performance

Varnish is an HTTP accelerator that significantly improves the performance of your web application by caching frequently accessed resources. In the context of Magento, Varnish plays a critical role in enhancing the speed and scalability of your e-commerce store.

The log snippet provided shows a typical request-response cycle between the client (192.168.10.10) and the Varnish cache server (varnish-host01). Let’s break down the key components:

Varnish Cache Configuration

Varnish is configured to use the “boot” VCL file, which defines the default behavior of the cache. The RECV subroutine in the VCL handles incoming requests and performs initial processing.

In this case, a GET request for /example-req-url is received with various headers including Host, User-Agent, Accept-Language, and Cookies.

Varnish Hashing

The HASH subroutine is called to determine how to store the cached object. Varnish uses a consistent hashing algorithm that distributes objects evenly across multiple cache servers in a cluster. This ensures load balancing and high availability.

If no matching object is found, Varnish proceeds with a “MISS” and sends the request to the backend server (Apache/2.4.52) for processing.

Cache Hit or Cache Miss

In this particular case, we observe a cache hit (“HIT”) as indicated by the X-Magento-Cache-Debug header. This means that Varnish found a matching cached object in memory and did not need to fetch it from the backend server.

The response headers show that the content is compressed (Content-Encoding: gzip) for faster transmission, and various security-related headers are present, such as X-Frame-Options, X-XSS-Protection, and Content-Security-Policy.

Varnish and Magento Integration

For Magento to work effectively with Varnish, you need to ensure that the Varnish configuration is properly set up. This includes:

  1. Configuring the varnish.url setting in your Magento config file to point to the Varnish server.
  2. Enabling full-page caching and integrating the Varnish module provided by Magento or third-party extensions like Varnish Cache Server Plugin.
  3. Clearing the cache regularly to ensure fresh content is served.

Best Practices for Optimizing Varnish Performance

To make the most of Varnish in your Magento store, consider the following best practices:

  1. Tune Expire Headers: Configure your backend server (Apache/Nginx) to set appropriate expire headers that match your cache strategy.
  2. Use ESI (Edge Side Includes): ESI allows you to include dynamic content within static cached pages, reducing the number of requests needed for each page load.
  3. Control Cacheability: Use cache control headers like Cache-Control and Expires wisely to ensure only the intended objects are cached.
  4. Monitor Cache Efficiency: Regularly analyze your Varnish logs and statistics to identify opportunities for improving cache hit rates.

In conclusion, understanding how Varnish works is crucial for optimizing Magento performance. By properly configuring and managing your Varnish cache, you can deliver faster load times, improve user experience, and scale your e-commerce store more effectively.

For further information on implementing Varnish with Magento, I recommend checking out the official documentation and resources available at Laravel Company.

Cache Performance Admin Configuration

Our network