Clearing cache from command line behind a proxy

Posted by Sysadmin 4 lyfe on November 4, 2014

Quick trick, adapted from something my boss showed me, on how to clear a cache from behind a proxy.

If you’re using a web browser you can just use CTRL+F5, which I think most people know already. Squid proxies will respect the “no-cache” header, flush the local copy and retrieve a fresh copy from the source.

At the command line this can be done as follows:

curl -H 'Cache-Control: no-cache' $URL

Which has the same effect. This is useful when you get a yum error such as: \
[Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404"
Trying other mirror.

Which is because the repomd.xml is out of date and refers to a repo db that no longer exists. Therefore you need to flush the proxy cache and yum cache as follows:

curl -H 'Cache-Control: no-cache'
yum clean all