cacheport

Ecosystem · Rust

crates.io cache for Cargo in CI

Cargo can swap crates.io for a mirror without touching Cargo.toml or Cargo.lock. Cacheport serves the sparse index and crate files, so cargo build fetches from your region.

CP-CARGOManifest
Upstream
index.crates.io and static.crates.io
Endpoint
sparse+https://acme.cacheport.cc/cargo/index/
Config
Source replacement in .cargo/config.toml
Token
CARGO_REGISTRIES_CACHEPORT_TOKEN
Cargo.lock
Unchanged, checksums verified
Crates
Cached forever, immutable

How Cargo caching works

Source replacement tells Cargo that another registry holds exactly the same crates as crates.io. Cargo keeps writing crates.io as the source in Cargo.lock and keeps verifying every crate against its checksum, while all downloads go to Cacheport.

Cacheport uses the sparse index protocol, so Cargo only downloads index files for the crates you actually depend on.

What gets cached
Sparse index files
Refreshed every 5 minutes, last good copy on failure.
.crate files
Cached forever, served byte-identical.
Git dependencies
Fetched directly by Cargo, not through the registry.

Set it up

.cargo/config.toml

.cargo/config.toml
[registries.cacheport]
index = "sparse+https://acme.cacheport.cc/cargo/index/"

[source.crates-io]
replace-with = "cacheport"

Token

shell
export CARGO_REGISTRIES_CACHEPORT_TOKEN="Bearer $CACHEPORT_TOKEN"
cargo build --locked

Cargo reads registry tokens from CARGO_REGISTRIES_<NAME>_TOKEN. Commit the config file; keep the token in CI secrets.

Use it in CI

Store the token as a secret named CACHEPORT_TOKEN, then pick your provider.

GitHub Actions

.github/workflows/ci.yml
jobs:
  test:
    runs-on: ubuntu-latest
    env:
      CARGO_REGISTRIES_CACHEPORT_TOKEN: Bearer ${{ secrets.CACHEPORT_TOKEN }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo test --locked

More for GitHub Actions: GitHub Actions setup guide.

GitLab CI

.gitlab-ci.yml
test:
  image: rust:1
  script:
    - export CARGO_REGISTRIES_CACHEPORT_TOKEN="Bearer $CACHEPORT_TOKEN"
    - cargo test --locked

More for GitLab CI: GitLab CI setup guide.

Pair it with sccache

Downloading crates is only part of a cold Rust build; compiling them is the rest. The Build Cache service speaks the protocol sccache uses for remote storage, so compiled dependencies can be shared between runners too.

Troubleshooting

Errors that usually mean the public registry is the bottleneck, and what Cacheport changes about them.

Questions

Does source replacement change Cargo.lock?

No. Cargo still records crates.io as the source, so lockfiles work with and without Cacheport.

Can I publish through Cacheport?

No. Publish to crates.io with cargo publish as usual.

Does it cache rustup toolchains?

No, the Cargo endpoint serves crates only. Cache toolchains with your CI provider's cache.

Other ecosystems people set up next

Start on the free plan

20 GB of cache, every registry, unlimited users. Upgrade when your pipelines outgrow it.