How to purge / clear Varnish cache for a single URL

varnish cache

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.

What is the need for a Varnish cache?

The need for varnish cache is to boost up the loading speed of your website and reduce the load on servers.

It is also possible that when a website has new content, showing you the cached results would be irritating and annoying.

What is Varnish Cache?

It is a web application accelerator that is also commonly known as caching HTTP reverse proxy.

It really works fast and boosts up the speed of loading a website, which all depends on server architecture.

Purging can only be possible when you select an object and discard it.

If you like our content, we are sure you will love our plans. WPoven offers FREE Business emails, WP support & Dev support, FREE SSD, SSL, FREE Premium themes & Plugins. You can host unlimited websites & get Dedicated servers with plan starting just $16.61.

Plans & Features

WpOven

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> <script defer src="https://www.wpoven.com/wp-content/cache/autoptimize/js/autoptimize_c40deb9a4fcff35750a05475f2b8ca96.js"></script></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/"