Manually purging URLs from Varnish

×

Error message

Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in _menu_load_objects() (line 569 of /homepages/46/d762693627/htdocs/dc/includes/menu.inc).
Manually purging URLs from Varnish

You can manually purge URLs from Varnish by running either of the commands below.

In this example, the ATB Contact Us page is removed from the cache:

# Method 1, using curl (can be run anywhere)

curl -X PURGE --head 'http://www.parques-e-ingressos.com.br/contacte-nos'

  

# Method 2, using varnishadm (needs to be run on the Varnish server)

sudo varnishadm 'ban req.http.host == www.parques-e-ingressos.com.br && req.url == /contacte-nos'

To clear all content (html, images, etc) for a particular website you can do:

sudo varnishadm 'ban req.http.host == www.orlando-ticket-deals.co.uk'

To clear all html for a particular website you can do:

sudo varnishadm 'ban req.http.host == www.orlando-ticket-deals.co.uk && obj.http.content-type ~ "html"'

 

To clear all jpegs for a particular website you can do:

 

sudo varnishadm 'ban req.http.host == www.orlando-ticket-deals.co.uk && obj.http.content-type ~ "image/jpeg"'

To clear all content matching a pattern for a particular website:

// Clear everything with "Disney" in the path:

sudo varnishadm 'ban req.http.host == "www.orlando-ticket-deals.co.uk" && req.url ~ "Disney"'

  

// Clear images matching a certain imagecache profile:

sudo varnishadm 'ban req.http.host == "www.orlando-ticket-deals.co.uk" && req.url ~ "imagecache/otd-squeeze-main-special-offer-keyline-only"'

  

// Clear advagg cached content on OTD:

sudo varnishadm 'ban req.http.host == "www.orlando-ticket-deals.co.uk" && req.url ~ "advagg_css"'

  

// Clear all /phx/ content:

sudo varnishadm 'ban req.url ~ "^/phx/"'

  

// Clear all cached Solr search results pages on all domains:

sudo varnishadm 'ban req.url ~ "apachesolr_search"'

 

 

// Clear all DSD Legacy API cached paths:

sudo varnishadm 'ban req.url ~ "/api-dsd/"'

We can see verify this working by using curl to request this URL and display the headers:

# Check page is in cache - if it is we should see the header "X-Varnish-Cache: HIT"

[rangi@336643-web4 modules]$ curl --head 'http://www.parques-e-ingressos.com.br/contacte-nos'

HTTP/1.1 200 OK

Server: nginx/0.8.55

Date: Thu, 18 Jul 2013 12:54:36 GMT

Content-Type: text/html; charset=utf-8

Connection: keep-alive

X-Powered-By: PHP/5.3.3

Cache-Control: public, max-age=86400

Last-Modified: Thu, 18 Jul 2013 12:54:11 +0000

Expires: Sun, 11 Mar 1984 12:00:00 GMT

Vary: Cookie

ETag: "1374152051"

Content-Length: 19193

Accept-Ranges: bytes

X-Varnish: 1385367780 1385367094

Age: 24

Via: 1.1 varnish

X-Varnish-Cache: HIT

  

# Remove the URL from the Varnish cache:

[rangi@336643-web4 modules]$ sudo varnishadm 'ban req.http.host == www.parques-e-ingressos.com.br && req.url == /contacte-nos'

  

# Check that it was removed - we should see the header "X-Varnish-Cache: MISS"

[rangi@336643-web4 modules]$ curl --head 'http://www.parques-e-ingressos.com.br/contacte-nos'

HTTP/1.1 200 OK

Server: nginx/0.8.55

Date: Thu, 18 Jul 2013 12:54:44 GMT

Content-Type: text/html; charset=utf-8

Connection: keep-alive

X-Powered-By: PHP/5.3.3

Cache-Control: public, max-age=86400

Last-Modified: Thu, 18 Jul 2013 12:54:42 +0000

Expires: Sun, 11 Mar 1984 12:00:00 GMT

Vary: Cookie

ETag: "1374152082"

Content-Length: 19193

Accept-Ranges: bytes

X-Varnish: 1385367855

Age: 0

Via: 1.1 varnish

X-Varnish-Cache: MISS

  

# Now that the page has been requested once, the next request should be a HIT:

[rangi@336643-web4 modules]$ curl --head 'http://www.parques-e-ingressos.com.br/contacte-nos'

HTTP/1.1 200 OK

Server: nginx/0.8.55

Date: Thu, 18 Jul 2013 12:54:45 GMT

Content-Type: text/html; charset=utf-8

Connection: keep-alive

X-Powered-By: PHP/5.3.3

Cache-Control: public, max-age=86400

Last-Modified: Thu, 18 Jul 2013 12:54:42 +0000

Expires: Sun, 11 Mar 1984 12:00:00 GMT

Vary: Cookie

ETag: "1374152082"

Content-Length: 19193

Accept-Ranges: bytes

X-Varnish: 1385367951 1385367855

Age: 2

Via: 1.1 varnish

X-Varnish-Cache: HIT

blog tag: