Deleting Cached file/url from Varnish

Sometimes you might want to delete a file/url from varnish because it has been updated. Its pretty easy. Eg: bukalapak previously store KTP (literally: Resident Identity Card), we don't want it anymore so we need to delete image files that has been stored inside varnish. So, this is how I did it.

Get into varnish CLI

Issue this command.

# sudo varnishadm

You will get this output.

root@salya:/home/syseng# varnishadm  
200  
-----------------------------
Varnish Cache CLI 1.0  
-----------------------------
Linux,3.2.0-4-amd64,x86_64,-smalloc,-smalloc,-hcritbit  
varnish-4.0.3 revision b8c4a34

Type 'help' for command list.  
Type 'quit' to close CLI session.

varnish>  
Delete Uri

You can use regex for the url you want, for example ban req.url ~ "logo.*[.]png". On my case, I use this command.

ban req.url ~ "/uploads/lalalal*"  

Aaand that's it.

Lukman

Radio astronomer pretending to be system engineer.

Bandung, Indonesia