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:

http://swcdn.apple.com/content/downloads/55/52/041-7956/icd6dyhgzn9kpvhrdx5ugyhgrejdymf2du/iPhoto9.4.3Update.pkg

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 10.10.10.153 TCP_REFRESH_HIT/200 555236637 GET http://swcdn.apple.com/content/downloads/55/52/041-7956/icd6dyhgzn9kpvhrdx5ugyhgrejdymf2du/iPhoto9.4.3Update.pkg - DIRECT/17.253.35.203 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 http://swcdn.apple.com/content/downloads/55/52/041-7956/icd6dyhgzn9kpvhrdx5ugyhgrejdymf2du/iPhoto9.4.3Update.pkg

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://swcdn.apple.com/content/downloads/55/52/041-7956/icd6dyhgzn9kpvhrdx5ugyhgrejdymf2du/iPhoto9.4.3Update.pkg
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 10.10.10.153 TCP_MISS/200 555236653 GET http://swcdn.apple.com/content/downloads/55/52/041-7956/icd6dyhgzn9kpvhrdx5ugyhgrejdymf2du/iPhoto9.4.3Update.pkg - DIRECT/17.253.35.203 application/octet-stream

Last updated: 15/08/2015