Skip to content

Cache public repositories for slow or offline sites

What you'll learn:

  • What the upstream cache is, and how it differs from importing packages
  • How to add a cache target and read the page
  • How to prove that the cache works (MISS, then HIT)
  • How to point machines at it, and how to feed an offline site

Time: ~20 minutes
Prerequisites: An administrator account, and the depot-cache service running (it is part of the standard installation). The upstream_cache feature must be part of your licence.


What the upstream cache is

When forty machines each run apt-get install curl against archive.ubuntu.com, the same package crosses your internet link forty times. The upstream cache sits in the middle: the first machine that asks for a file triggers one download, and every other request is served from Repod's disk. If the public mirror goes down, files already cached are still served.

It is not the same thing as importing a package into Repod:

Upstream cache Import and mirror
What clients receive The upstream's files, byte for byte, with the upstream's own signature Packages Repod has validated, signed with Repod's key
Checks None. It is a relay Antivirus, CVE scan, security policy
What fills it Whatever clients request What you import
What it is for Bandwidth and availability Curation and control

The cache does not check anything

A package served from the cache has not been scanned, and your CVE policy and your content filters do not see it. Use it to save bandwidth for what you already trust (the official Ubuntu or AlmaLinux mirrors), and use the import path for anything that must be validated. The two can be used together.


Step 1 — Open the page

Open Linux → Cache upstream. The page has two parts: a form to add a target, and the list of targets already configured. A target is one public repository you want to cache.

The Add a target form, pre-filled from the Ubuntu preset: identifier, label, format, upstream base URL, maximum cache size and eviction delay

Figure 1 — Adding a target.

  1. Distribution prédéfinie. Choose a preset, such as Ubuntu (tous les codenames), Debian, AlmaLinux 9, Rocky Linux 9, Fedora 43 or Alpine 3.21, and the fields below fill themselves. Keep Personnalisé for any other repository.
  2. Identifiant. A short name, used in the address clients will use. Here ubuntu.
  3. Format. APT, RPM or APK. It decides how the cache treats files: packages are kept for a year, indexes such as InRelease only ten minutes, so you never serve stale metadata.
  4. URL de base upstream. The real public repository.
  5. Taille max cache (Go). The disk space this target may use. We chose 1 GB for the test; the default is 10.
  6. Éviction après (jours). A file nobody requested for this many days is removed. 30 by default.
  7. Ajouter la cible. Creates the target.

Step 2 — Read the list of targets

The configured targets: the target name, its format, its proxy path, its status and the Disable, Purge and Delete buttons

Figure 2 — The configured targets.

  1. Cibles configurées. How many targets exist.
  2. Chemin proxy. The path under which the cache serves this target: /upstream/apt/ubuntu/. Clients use it after the address and port of the cache.
  3. Statut. Actif means the target is served.
  4. Désactiver. Stops serving the target but keeps its cached files, ready to be switched back on.
  5. Purger. Empties the cached files and keeps the target. The next request for any file is a new download.
  6. Supprimer. Removes the target. The files already cached are not deleted: purge first if you want the space back.

Step 3 — Check that it works

The cache listens on its own port, 8090 unless your administrator changed UPSTREAM_CACHE_PORT. Every answer carries an X-Repod-Cache header that says where it came from. Request the same file twice:

for i in 1 2; do
  curl -s -D - -o /dev/null http://repod.example.com:8090/upstream/apt/ubuntu/dists/jammy/InRelease \
    | grep -i x-repod-cache
done

On our instance the first request, which downloaded 270 KB from archive.ubuntu.com, answered MISS. The second answered HIT: nothing left the machine. A third value, STALE, means the upstream was unreachable but an older cached copy was served. That is the resilience: a file already cached is never blocked by an outage of the public mirror.


Step 4 — Point your machines at it

A machine uses the cache exactly as it would use the real mirror, with a different address. For APT:

# /etc/apt/sources.list.d/repod-cache.list
deb http://repod.example.com:8090/upstream/apt/ubuntu jammy main restricted universe multiverse
deb http://repod.example.com:8090/upstream/apt/ubuntu jammy-updates main restricted universe multiverse
deb http://repod.example.com:8090/upstream/apt/ubuntu jammy-security main restricted universe multiverse

Signatures are still checked against the upstream's key, because the cache does not re-sign anything. Do not disable signature checking on the client. For RPM, use a .repo file whose baseurl points at /upstream/rpm/<identifier> and keep gpgcheck=1 with the distribution's own key.


Step 5 — Feed a site with no internet

An offline site cannot fill its own cache, since there is nothing to download from. The principle is to fill a cache elsewhere and carry it over:

  1. On a machine with internet access (the relay), run the same cache and warm it with the real tools: point a test machine at it and run apt-get update and the installs your offline fleet needs.
  2. Export the target's cache directory to a removable medium with scripts/cache-transfer.sh export.
  3. On the offline site, create the same target (same identifier) from this page. Creating it only writes configuration, it makes no network call.
  4. Import the archive with scripts/cache-transfer.sh import. No restart is needed.

Repeat the cycle regularly to bring in security updates. The complete procedure, with every command, is in Upstream cache.


Disk space and clean-up

Size the Taille max from what your fleet really installs, not from the size of the public mirror: only requested files are kept, so a small fleet needs a few gigabytes. When a target reaches its maximum, the least recently used files are removed first.

If Purger answers that the purge is incomplete, the cache was written by another system user than the backend's (typically after an upgrade). Empty the target's folder under /repos/upstream-cache/data/ as an administrator of the host, then try again.


What's next