Eric Radman : a Journal

A Mirror Cache

I regularly rebuild machines in my home lab. To cut down on the delay and bandwidth required to download the same package multiple times a forward proxy can be employed to cache and serve files.

Squid Configuration

cache_dir ufs /var/squid/cache 67275 16 256
refresh_pattern -i .rpm$ 129600 100% 129600 refresh-ims override-expire
maximum_object_size 4096 MB
cache_replacement_policy heap LFUDA
  1. Keeping a maximum of 67GB of data, spread out over the 16 directories and 256 subdirectories
  2. Since this cache is used for packages there is no need to HTTP cache control headers. Instead raise up the expiration times (in minutes) to provide a lifetime of 90 days
  3. By default squid does not cache objects over 4MB, crank this up to 4GB
  4. Enable dynamic aging

Finally, initialize the cache directory

squid -z

Manual Verification

A cache hit is indicated by the X-Cache header

$ src=http://eradman.com/entrproject/code/entr-5.2.tar.gz
$ curl --proxy http://192.168.1.1:3128 -D - -s -o /tmp/entr-5.2.tgz $src
HTTP/1.1 200 OK
Content-Length: 25834
Content-Type: application/octet-stream
Date: Fri, 19 Aug 2022 05:23:53 GMT
Last-Modified: Thu, 05 May 2022 15:19:44 GMT
Server: OpenBSD httpd
X-Cache: MISS from xa10.eradman.com
Via: 1.1 xa10.eradman.com (squid/5.5)
Connection: keep-alive

$ sleep 170

$ curl --proxy http://192.168.1.1:3128 -D - -s -o /tmp/entr-5.2.tgz $src
HTTP/1.1 200 OK
Content-Length: 25834
Content-Type: application/octet-stream
Date: Fri, 19 Aug 2022 05:23:53 GMT
Last-Modified: Thu, 05 May 2022 15:19:44 GMT
Server: OpenBSD httpd
Age: 175
X-Cache: HIT from xa10.eradman.com
Via: 1.1 xa10.eradman.com (squid/5.5)
Connection: keep-alive

Client Configuration

On RPM-based systems yum will use this cache after setting the proxy option in /etc/yum.conf or /etc/dnf.conf

proxy=http://192.168.2.1:3128

For everything else set SHELL environment variables

export http_proxy="http://192.168.2.1:3128"