Hoppa till huvudinnehåll
Menu

Den här sidan använder cookies. Om du fortsätter använda sidan så accepterar du användandet av cookies. Läs mer om cookies

Jag förstår

Purge cache-tags with Varnish

In this blog post I am going to go through a step by step setup for using the Varnish purge module together with Purge and Drupal 8.

Please read this about updates done since the blog post were written.

In this blog post I am going to go through a step by step setup for using the Varnish purge module together with Purge and Drupal 8.

We have started to work on the Varnish purge module and we are using it some of our projects. The Varnish purge module is a fork of the Generic HTTP Purger with some minor changes.

To use Purge and Varnish Purge you need to have a working setup with Varnish already, for an example VCL, see the end of the blog post.

First install Purge and Varnish purge modules. For Purge to work normally you also have to install Purge Tokens (to get cache-tag support), Purge UI and Purge Drush if you want Drush integration. Also install the Cron processor and Core tags queuer.

Modules to use with Varnish Purge

Now head over to the configuration for Purge, found at => Configuration → Development → Performance – then click the tab Purge (some times you need to rebuild cache to make the tab become visible)

Click Add Purger, and Choose Varnish Purger

Add Varnish purger

Then you get a new varnish purger with an unique id. Click on the small arrow beside the name, and then configure. Normally, Type: Tag is set as default, and that is what we are using for this blog post.

Varnish purger settings

Our dev Varnish is on the local environment . So I use 127.0.0.1, and port 80 for incoming http purges – these settings could be different in your own setup.

Click tokens in the tabs to get the token for cache tags. In this case – [invalidation:expression], so I just copy that.

Click on the Headers tab.

The name of the Header added by Purge module is Purge-Cache-Tags – so add that for Header and in the field Value, past the token. And then, save the configuration.

Purge header

Just for the initial setup I click on the Configure logging, and put out all logging on so you easily could debug it in syslog or watchdog. (When I finish my setup, I just keep Emergency, Alert and Critical.)

Logging

That is it for the Purge configuration in Drupal – now we need to add needed configuration to the Varnish VCL.

In this example VCL Varnish removes the cache-tags and just replaces them with HIT or MISS before delivering in to the browser – so your header not get to crowded. If you want to have the cache-tags output for debugging or other reasons, just comment out these lines in the VCL and restart Varnish:

unset resp.http.Purge-Cache-Tags;

and


if (obj.hits > 0) {
  set resp.http.Purge-Cache-Tags = "HIT";
}
else {
  set resp.http.Purge-Cache-Tags = "MISS";
}


That is it, happy invalidation of caches :-)

 

Top photo by Aaaarrrrgggghhhh! License GPL 2.0

Vi hjälper dig nå resultat. Kontakta oss Ring direkt på 08-20 90 04.

Cache in Drupal 8: How it worked, and what we wanted to be solved in D8

If you just want your content to be cached before Drupal 8, there were almost no problems, just turn on caching for anonymou…
MDN

Cache in Drupal 8: Introduction

In a series of blog posts we will go through how caching works in Drupal 8, to try to demystify the caching layer in Drupal …
MDN