Improve Cache Details documentation (#49)

Updates the documentation on how the cache works to more
closely match the implementation and to explain some of the design decisions.
This commit is contained in:
Ed Morley 2022-03-05 09:04:16 +00:00 committed by GitHub
parent 3bb3a9a087
commit 5b2b053862
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,27 +61,40 @@ a more stable experience, please use a fixed revision or tag.
## Cache Details ## Cache Details
The cache currently caches the following directories: This action currently caches the following files/directories:
- `~/.cargo/bin`
- `~/.cargo/registry/index` - `~/.cargo/registry/index`
- `~/.cargo/registry/cache` - `~/.cargo/registry/cache`
- `~/.cargo/git` - `~/.cargo/git`
- `~/.cargo/.crates.toml`
- `~/.cargo/.crates2.json`
- `./target` - `./target`
This cache is automatically keyed by: This cache is automatically keyed by:
- the github `job`, - the github [`job_id`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_id),
- the rustc release / host / hash, and - the rustc release / host / hash, and
- a hash of the `Cargo.lock` / `Cargo.toml` files (if present). - a hash of all `Cargo.lock` / `Cargo.toml` files found anywhere in the repository (if present).
- a hash of the `rust-toolchain` / `rust-toolchain.toml` files (if present). - a hash of all `rust-toolchain` / `rust-toolchain.toml` files in the root of the repository (if present).
An additional input `key` can be provided if the builtin keys are not sufficient. An additional input `key` can be provided if the builtin keys are not sufficient.
Before persisting, the cache is cleaned of intermediate artifacts and Before being persisted, the cache is cleaned of:
anything that is not a workspace dependency. - Any files in `~/.cargo/bin` that were present before the action ran (for example `rustc`).
In particular, no caching of workspace crates will be done. For - Dependencies that are no longer used.
this reason, this action will automatically set `CARGO_INCREMENTAL=0` to - Anything that is not a dependency.
disable incremental compilation. - Incremental build artifacts.
- Any build artifacts with an `mtime` older than one week.
In particular, the workspace crates themselves are not cached since doing so is
[generally not effective](https://github.com/Swatinem/rust-cache/issues/37#issuecomment-944697938).
For this reason, this action automatically sets `CARGO_INCREMENTAL=0` to disable
incremental compilation, so that the Rust compiler doesn't waste time creating
the additional artifacts required for incremental builds.
The `~/.cargo/registry/src` directory is not cached since it is quicker for Cargo
to recreate it from the compressed crate archives in `~/.cargo/registry/cache`.
The action will try to restore from a previous `Cargo.lock` version as well, so The action will try to restore from a previous `Cargo.lock` version as well, so
lockfile updates should only re-build changed dependencies. lockfile updates should only re-build changed dependencies.
@ -90,3 +103,9 @@ Additionally, the action automatically works around
[cargo#8603](https://github.com/rust-lang/cargo/issues/8603) / [cargo#8603](https://github.com/rust-lang/cargo/issues/8603) /
[actions/cache#403](https://github.com/actions/cache/issues/403) which would [actions/cache#403](https://github.com/actions/cache/issues/403) which would
otherwise corrupt the cache on macOS builds. otherwise corrupt the cache on macOS builds.
## Known issues
- The cache cleaning process currently only runs against the build artifacts under
`./target/debug/`, so projects using release or cross-compiled builds will experience
larger cache sizes.