Clearing an entry from varnish

Submitted by Micheas on Tue, 02/28/2012 - 11:00

Varnish is a reverse proxy that allows you to fine tune your caching with all of the power of C.

Unfortunately, sometimes you need to tell varnish that one of the millions of files in the cache should be refreshed sooner than you would normally want.

Fortunately Varnish includes a untility called varnishadm that allows you to manually remove a single url from the cache, or even all the urls that match a regular expression.

The instructions below assume that your varnish server is varnish.example.com, change this to your hostname. (Possibly localhost if you are on the varnish server) And that your varnish admin is running on port 6082 (that is the default but check your vcl file to see what it is on your server) and that you are running debian or ubuntu, because that it what we run most of the time.

Start the varnishadm shell

varnishadm -T varnish.example.com:6082 -S /etc/varnish/secret

now that you are in you will be greeted with a command prompt. At the prompt type:

purge.url file/that/you/want/purged.css

Do not include the host name, and realize that if you are caching for multiple host names you are going to be clearing the cache for all of them.