Squid -k rotate and clear squid cache

Squid -k rotate just a way to ‘clear squid cache’ although it doesn’t clear squid cache (a real cache). But it helps when browsers ’stuck’ with caches (refresh/reload pages doesn’t work)

This description from Squid FAQ
Cache/Log (Squid 1.x) or Swap.State (Squid 2.x)
This file has a rather unfortunate name. It also is often called the swap log. It is a record of every cache object written to disk. It is read when Squid starts up to “reload” the cache. If you remove this file when squid is NOT running, you will effectively wipe out your cache contents. If you remove this file while squid IS running, you can easily recreate it. The safest way is to simply shutdown the running process:
% squid -k shutdown
This will disrupt service, but at least you will have your swap log back. Alternatively, you can tell squid to rotate its log files. This also causes a clean swap log to be written.
% squid -k rotate

For Squid-1.1, there are six fields:
fileno: The swap file number holding the object data. This is mapped to a pathname on your filesystem.
timestamp: This is the time when the object was last verified to be current. The time is a hexadecimal representation of Unix time.
expires: This is the value of the Expires header in the HTTP reply. If an Expires header was not present, this will be -2 or fffffffe. If the Expires header was present, but invalid (unparsable), this will be -1 or ffffffff.
lastmod: Value of the HTTP reply Last-Modified header. If missing it will be -2, if invalid it will be -1.
size: Size of the object, including headers.
url: The URL naming this object.

If you remove the swap.state while Squid is not running, you will not lose your entire cache. In this case, Squid will scan all of the cache directories and read each swap file to rebuild the cache. This can take a very long time, so you’ll have to be patient.

By default the swap.state file is stored in the top-level of each cache_dir. You can move the logs to a different location with the cache_swap_log option.

Leave a Reply