Varnish – Remove file(s) from the cache
Varnish caches files. So if you replace a file on the server by a new one and this file is not refreshed when you try to access to it via your browser it probably means that Varnish still keep an expired version in his cache. (Or you didn’t clear the cache of your browser)
To purge a file from the cache, here is the process:
- Log in the varnish that manage this file.
- Check on what port the varnish CLI is running (example 127.0.0.1:2000)
- Connect to the CLI using varnishadm. It should looks like something like this :
# sudo varnishadm -T 127.0.0.1:2000 -S /etc/varnish/secret
- Once you are connected you have to give the URL of file(s) you want to purge. You have to use regular expression :
-> Imagine that you want to purge this image :Â http://static.mauitu.com/images/bg-footer.jpgÂ the command will be :
-> if you want to purge all the images contained in /images :
this will purge all the the images folder
-> if you want to purge all the images contained in /images and his subdirectories:
this will purge all the the images folder.
This will purge the cache for the file after his next call. Then all the other request to the fille will hit the cache just like before. So if you decide to modify again a file, you will have to type thos command again
To exit the varnish CLI type :