Removing an entry from Squid proxy's cache

Sometimes there is a need to delete a file that squid proxy has already downloaded and stored in its cache.

For this example we are using the following URL, an iPhoto update which I had problems downloading:

When this file is requested by a client the following entry is created in the access log showing the client receiving the version stored in the cache (cache hit):

==> /var/log/squid/access.log <==
1436637066.764 246801 TCP_REFRESH_HIT/200 555236637 GET - DIRECT/ application/octet-stream

The store log will also show this file being found:

==> /var/log/squid/store.log <==
1436637066.764 RELEASE 00 00000A43 0252C4D00A906FB95B4C1EAB5D1CB063  200 1436636820 1365769909 1436651220 application/octet-stream 555236214/-490 GET

The easiest way to remove entries from squid's cache is to use the squidclient utility, to install on debian just run the following command (Other linux distributions may vary):

$ sudo apt-get install squidclient

Once installed we can send a PURGE command to squid running on localhost:

$ squidclient -m PURGE
HTTP/1.0 200 OK
Server: squid/2.7.STABLE9
Date: Sat, 11 Jul 2015 17:52:43 GMT
Content-Length: 0
Expires: Sat, 11 Jul 2015 17:52:43 GMT
X-Cache: MISS from rigby
X-Cache-Lookup: NONE from rigby:3128
Connection: close

After this command has been run, when a client requests the file again for the first time the access log will show a cache miss, resulting in a fresh version of the file being downloaded:

==> /var/log/squid/access.log <==
436637462.137 285349 TCP_MISS/200 555236653 GET - DIRECT/ application/octet-stream

Last updated: 15/08/2015