Exclude checkout and customer modules/section of magento using varnish-turpentine combination

Exclude checkout and customer modules/section of magento using varnish-turpentine combination

September 30, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Exclude checkout and customer modules/section of magento using varnish-turpentine combination

Cache Control for Magento Checkout and Customer Modules Using Varnish + Turpentine

Introduction

Caching is a critical component of optimizing your Magento store’s performance. However, certain sections like the checkout process and customer account modules require real-time data and should not be cached by the Varnish accelerator. In this post, we’ll guide you through effectively excluding these sensitive areas using the powerful combination of Varnish and Turpentine.

Understanding the Problem

By default, Magento’s integration with Varnish via the Turpentine extension does not differentiate between cacheable and non-cacheable content. This means that your checkout process, customer login pages, and other vital dynamic sections are being cached by Varnish, leading to potential errors or a degraded user experience.

The Solution: Exclude Critical Sections

Step 1: Disable Caching for Specific Pages

At the core of your issue lies Magento’s default behavior of caching all content. To change this, you’ll need to disable caching specifically for your checkout and customer areas in the Magento backend:

  1. Navigate to System > Configuration > Advanced > System.
  2. Expand the Disable Modules Output configuration.
  3. Check the boxes next to ‘Mage_Checkout’ and ‘Mage_Customer’.

This step alone won’t solve the issue entirely, as Varnish may still cache certain resources like images or stylesheets linked within these pages.

Step 2: Manipulate VCL File

The real power lies in manipulating the Varnish Cache-Loader (VCL) file to specifically exclude your checkout and customer URLs from being cached. Here’s how:

  1. Access your Varnish server using SSH.
  2. Navigate to the directory holding your VCL files, usually found at /etc/varnish/. The exact path depends on your specific Varnish installation.
  3. Locate the default.vcl file and open it with a text editor, for example: nano /etc/varnish/default.vcl.

You’ll need to add new subrules within the vcl_recv function to identify requests from checkout and customer URLs and mark them as non-cacheable:

sub vcl_recv {
  # Exclude checkout pages
  if (req.url ~ "^/checkout/") {
    set beresp.uncacheable = true;
  }

  # Exclude customer account pages
  if (req.url ~ "^/customer/") {
    set beresp.uncacheable = true;
  }

  # Add more exclusions as necessary...

  # The rest of your VCL logic...
}

In this example, we’re using regular expressions to match URLs starting with /checkout/ and /customer/. Any requests that satisfy these conditions will be marked as uncacheable by setting beresp.uncacheable to true.

Step 3: Reload the VCL Configuration

After updating your default.vcl file, you must reload or restart the Varnish service for the changes to take effect:

sudo service varnish restart

Verifying the Changes

To confirm that your exclusions are working as expected:

  1. Browse to a page within your checkout process or customer account area.
  2. Open the browser’s developer tools and check the network tab.
  3. Look for any requests made during this page load; none of them should be marked as cached by Varnish.

Conclusion

Successfully excluding critical Magento modules like checkout and customer from Varnish caching requires a combination of disabling output in the Magento backend and manipulating the VCL file on your Varnish server.

Remember, optimizing cache settings is an iterative process that often involves trial and error. Always monitor your site’s performance and user experience after making changes to ensure you’re achieving the desired balance between speed and functionality.

For more advanced caching strategies and optimization techniques for Magento, we recommend exploring our comprehensive guide on Magento Performance Optimization produced by our experienced team at Laravel Company.

Checkout Cache Performance Extensions

Our network