Local distfiles cache

When several machines are running Gentoo on the same local area network, it is a good idea to cache distfiles on one of them and let the rest download from that one. This saves bandwidth for both the network owner and the public source mirrors.

Setting up the server
Select the machine that is going to serve the local distfiles cache and set it up. It will need to have enough free disk space to store all of the packages that are used by any machines on the network. The server machine will also need to be available whenever any other computer emerges a new package, and other computers on the network will need to be able to reach it using a static IP address or hostname.

There are a number of ways in which the cache can be implemented. This page describes a simple setup using.

Installing software
Install net-misc/apt-cacher-ng:

Configuring for Gentoo
Apt-cacher-ng includes support for the Gentoo source mirrors, but some configuration is still needed. Since it is designed primarily for use with the Debian package management system, there are some types of files used in Gentoo distfiles which by default it refuses to download. To change this behavior, create the file :

Configuring mirrors
Configure the list of public Gentoo mirrors from which apt-cacher-ng will download source packages:

Starting the service
Now start the cache service:

To start the service at boot:

Setting up clients
On all machines which are to use the distfiles cache (including the cache server itself), add the following to :

Enhancements

 * Emerge net-misc/apt-cacher-ng with the  use flag and mount  on  on the cache server. This avoids storing two copies of all of the packages installed on that server.

Open issues

 * Apt-cacher-ng installs a cron job to delete unreferenced files from the cache. Since the Gentoo cache contains no index files, this probably deletes either everything or nothing from it.


 * If  is set to   in, apt-cacher-ng will cache the snapshots. This is good if multiple machines are set up to use webrsync, but in the preferable case that a local rsync mirror is being used, it is just a waste of space.

External resources

 * [//serverfault.com/a/559076 Running a Gentoo distfiles caching mirror on Debian]
 * [//www.unix-ag.uni-kl.de/~bloch/acng/html/ Apt-Cacher-NG User Manual]