Tutorials

How to purge / clear Varnish cache for a single URL

Varnish is a reverse web proxy accelerator that caches the HTTP contents. It can speed up requests by a factor of 500-1000 times. By caching and saving CPU time and database requests for content, varnish is able to server hundreds of consecutive requests per second.

In order to purge or clear Varnish cache, you can simply restart Varnish. This will clear the varnish cache.

/etc/varnish restart

or if you are using 'services' on your server, you can run the following on the command line

service varnish restart

In order to purge varnish cache for a specific URL, using CURL :

curl -X PURGE URL-to-PURGE

Running this command should provide an output like this :



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>200 Varnish cache has been purged for this object.</title>
  </head>
  <body>
    <h1>Error 200 Varnish cache has been purged for this object.</h1>
    <p>Varnish cache has been purged for this object.</p>
    <h3>Guru Meditation:</h3>
    <p>XID: 1398586940</p>
    <hr>
    <p>Varnish cache server</p>
  </body>
</html>

Clearing the varnish cache for a specific URL using varnishadm

To open the varnishadm console. use the following command to purge the URL http://www.example.com/some/url :

varnishadm -T 127.0.0.1:6082 -S /etc/varnish/secret ban "req.http.host == example.com && req.url == /some/url/"

Copyright © 2018 WPOven