# Caching & reuse

> Understand how dependency caches, compiler outputs and retained build state can reduce repeated work.

Source: https://www.sorus.run/docs/concepts/reuse
Reviewed: 2026-10-22

Rust builds reuse several kinds of data. Downloaded dependencies save a fetch, prebuilt dependencies and compiler outputs save repeated compilation, and a retained build directory can preserve work that Cargo considers fresh. These mechanisms have different compatibility rules, so a warm cache does not mean every part of a job can be skipped.

## Compatibility

Compatibility is checked across `Cargo.lock`, the resolved Rust toolchain, the Cargo command and arguments, the declared environment, the working directory and the machine class (`4 vCPU`, `8 vCPU` or `16 vCPU`). A different compiler, lockfile or feature set can invalidate earlier outputs even when a crate version is unchanged.

Sorus uses those inputs when selecting reusable state. Cargo still decides which units need rebuilding. A cache miss is an expected outcome: the job must perform the requested work when compatible state is unavailable.

## Reuse mechanisms

### Dependency locality and prebuilds

The dependency gateway retains public crate and Git content near execution, verifies crates against their recorded checksums and serves locked Git commits. In addition, Sorus reads `Cargo.lock` and prebuilds external crates (`crates.io` packages and commit-pinned Git dependencies) in an isolated preparation job before your check, build or test runs.

### Compiler outputs

The compiler cache can reuse compatible compilation outputs in a tenant's namespace across runs that share the same toolchain, dependency lockfile, flags and environment. Linked binaries, build-script execution and incremental compilation have different reuse behavior.

Inspect the job's reported cache activity and applied configuration when evaluating it. A faster run alone does not establish a cache hit, and an explicit compiler setting can change which units are cacheable.

### Private warm build state

Protected-branch and merge-queue CI runs can retain compatible workspace `target/` build state on the repository's trunk lineage. Subsequent pull requests, local `git worktree` runs and coding agents clone that prepared state into an isolated scratch volume and recompile only the crates affected by their changes, without downloading and unpacking the target directory on a runner.

Prebuilt state also affects automatic sizing. When no explicit machine size is passed, Sorus selects `4 vCPU`, `8 vCPU` or `16 vCPU` from the workspace dependency graph and available prebuilt state. The job's `size_decision` records the actual decision.

### Workflow caches

An `actions/cache` step belongs to the workflow and runner where it executes. Installing the Sorus client in GitHub Actions does not move that runner's filesystem or its cache into a managed Sorus job. The remote job receives the captured source and Sorus-managed state.

## Trust boundaries

Customer-produced build state and compiler outputs remain tenant-private. Shared public dependency content does not grant access to another customer's artifacts or source. Reuse requires both compatible inputs and the authority to read the retained data.

## Measuring reuse

Compare the same source, command, compiler and environment. Record which state was available and which mechanism reported a hit or miss. Cold runs and repeated warm runs answer different questions; report both when evaluating a workflow that encounters both.

A missing measurement should remain unknown. Do not infer cache behavior from timing alone or use a selected cache hit to represent every run. The [benchmark method](https://www.sorus.run/benchmarks/methodology) describes a comparable measurement.
