{"id":13595541,"url":"https://github.com/matthiaskrgr/cargo-cache","last_synced_at":"2025-05-15T01:09:26.259Z","repository":{"id":37381958,"uuid":"113244429","full_name":"matthiaskrgr/cargo-cache","owner":"matthiaskrgr","description":"manage cargo cache (${CARGO_HOME}, ~/.cargo/), print sizes of dirs and remove dirs selectively","archived":false,"fork":false,"pushed_at":"2023-06-04T10:29:12.000Z","size":1888,"stargazers_count":905,"open_issues_count":30,"forks_count":20,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-13T23:53:56.095Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matthiaskrgr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-05T23:31:11.000Z","updated_at":"2025-04-11T15:32:59.000Z","dependencies_parsed_at":"2024-06-09T16:21:01.812Z","dependency_job_id":"01bf159d-6989-473b-97c5-e322adfd0c49","html_url":"https://github.com/matthiaskrgr/cargo-cache","commit_stats":{"total_commits":1553,"total_committers":8,"mean_commits":194.125,"dds":"0.010302640051513157","last_synced_commit":"029748e2d305301c14ab73a8910bb0a1b0de45d1"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthiaskrgr%2Fcargo-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthiaskrgr%2Fcargo-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthiaskrgr%2Fcargo-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthiaskrgr%2Fcargo-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matthiaskrgr","download_url":"https://codeload.github.com/matthiaskrgr/cargo-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254254043,"owners_count":22039792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T16:01:52.042Z","updated_at":"2025-05-15T01:09:21.252Z","avatar_url":"https://github.com/matthiaskrgr.png","language":"Rust","readme":"## cargo cache\n\n[![Build Status](https://github.com/matthiaskrgr/cargo-cache/workflows/ci/badge.svg)](https://github.com/matthiaskrgr/cargo-cache/actions) \u003c!-- [![dependency status](https://deps.rs/repo/github/matthiaskrgr/cargo-cache/status.svg)](https://deps.rs/repo/github/matthiaskrgr/cargo-cache)' --\u003e\n[![Latest Version](https://img.shields.io/crates/v/cargo-cache.svg)](https://crates.io/crates/cargo-cache)\n[![libs.rs](https://img.shields.io/badge/libs.rs-gray.svg)](https://lib.rs/crates/cargo-cache)\n\nDisplay information on the cargo cache (`~/.cargo/` or `$CARGO_HOME`). Optional cache pruning.\n\n\n![Screenshot of cargo cache default output (it's listed below also in textual form)](data/screenshot_readme_f724ec8.png?raw=true \"Cargo Cache\")\n\n#### Key Features:\n* check the size of the cargo cache and its components (cmd: `cargo cache`)\n* do a simple cleanup removing checkouts but keeping original files needed for reconstruction on disk (`--autoclean`)\n* clean up everything (cargo will re-download as needed)\n* dry-run to see what would be removed (`--dry-run`)\n* recompress git repos (`--gc`)\n* search cache via regex queries (`cargo cache query \"reg.*x\"`)\n* print crates that take the most space (`--top-cache-items`)\n* alternative registries supported\n* remove files older or younger than X (`--remove-if-{older,younger}-than`)\n* builds and runs on `stable`, `beta` and `nightly` channel\n* purge cache entries not used to build a specified crate (`cargo cache clean-unref`)\n* print size stats on a local sccache build cache  (`cargo cache sc`)\n* verify extracted crate sources (`cargo cache verify`)\n\n#### Installation:\n```cargo install cargo-cache```\n\nor for the bleeding edge development version:\n\n```cargo install --git https://github.com/matthiaskrgr/cargo-cache cargo-cache```\n\n#### Default output (`cargo cache`):\nThis only calculates the sizes and does not touch anything:\n````\nCargo cache '/home/matthias/.cargo':\n\nTotal:                                4.22 GB\n  102 installed binaries:           920.95 MB\n  Registry:                           2.25 GB\n    Registry index:                 227.07 MB\n    4412 crate archives:            684.29 MB\n    2411 crate source checkouts:      1.34 GB\n  Git db:                             1.05 GB\n    113 bare git repos:             993.72 MB\n    9 git repo checkouts:            55.48 MB\n````\nTo learn more about the subdirectories inside the cargo home and what can be safely deleted, check `--info`.\n\n\n#### Usage:\n````\nUSAGE:\n    cargo cache [OPTIONS] [SUBCOMMAND]\n\nOPTIONS:\n    -a, --autoclean                        Removes crate source checkouts and git repo checkouts\n    -e, --autoclean-expensive              As --autoclean, but also recompresses git repositories\n    -f, --fsck                             Fsck git repositories\n    -g, --gc                               Recompress git repositories (may take some time)\n    -h, --help                             Print help information\n    -i, --info                             Print information cache directories, what they are for and what can be safely deleted\n    -k, --keep-duplicate-crates \u003cN\u003e        Remove all but N versions of crate in the source archives directory\n    -l, --list-dirs                        List all found directory paths\n    -n, --dry-run                          Don't remove anything, just pretend\n    -o, --remove-if-older-than \u003cdate\u003e      Removes items older than specified date: YYYY.MM.DD or HH:MM:SS\n    -r, --remove-dir \u003cdir1,dir2,dir3\u003e      Remove directories, accepted values: all,git-db,git-repos,\n                                           registry-sources,registry-crate-cache,registry-index,registry\n    -t, --top-cache-items \u003cN\u003e              List the top N items taking most space in the cache\n    -V, --version                          Print version information\n    -y, --remove-if-younger-than \u003cdate\u003e    Removes items younger than the specified date: YYYY.MM.DD or HH:MM:SS\n\nSUBCOMMANDS:\n    clean-unref    remove crates that are not referenced in a Cargo.toml from the cache\n    help           Print this message or the help of the given subcommand(s)\n    l              check local build cache (target) of a rust project\n    local          check local build cache (target) of a rust project\n    q              run a query\n    query          run a query\n    r              query each package registry separately\n    registry       query each package registry separately\n    sc             gather stats on a local sccache cache\n    sccache        gather stats on a local sccache cache\n    toolchain      print stats on installed toolchains\n    trim           trim old items from the cache until maximum cache size limit is reached\n    verify         verify crate sources\n````\n\n#### Show the largest items in the cargo home:\n````\ncargo cache --top-cache-items 5\n\nSummary of: /home/matthias/.cargo/bin/ (588.35 MB total)\nName         Size\nalacritty    38.40 MB\nxsv          29.78 MB\nrg           28.51 MB\ncargo-geiger 15.11 MB\nmdbook       12.39 MB\n\nSummary of: /home/matthias/.cargo/registry/src/ (3.11 GB total)\nName                         Count Average   Total\nmozjs_sys                    4     131.83 MB 527.31 MB\nwabt-sys                     2     83.73 MB  167.46 MB\nopenblas-src                 2     78.42 MB  156.84 MB\ncurl-sys                     6     18.47 MB  110.83 MB\nwinapi-x86_64-pc-windows-gnu 2     54.90 MB  109.80 MB\n\nSummary of: /home/matthias/.cargo/registry/cache/ (1.18 GB total)\nName        Count Average  Total\nmozjs_sys   10    29.45 MB 294.50 MB\ncurl-sys    16    3.03 MB  48.54 MB\nlibgit2-sys 18    2.54 MB  45.64 MB\nservo-skia  6     5.23 MB  31.39 MB\nopenssl-src 5     5.55 MB  27.73 MB\n\nSummary of: /home/matthias/.cargo/git/db/ (918.97 MB total)\nName         Count Average   Total\npolonius     1     136.63 MB 136.63 MB\nmdbook       1     111.45 MB 111.45 MB\nrust-rocksdb 2     33.31 MB  66.62 MB\nosmesa-src   2     28.45 MB  56.90 MB\nring         2     23.02 MB  46.04 MB\n\nSummary of: /home/matthias/.cargo/git/checkouts/ (3.80 GB total)\nName            Count Average   Total\nparity-ethereum 2     666.36 MB 1.33 GB\nxori            1     372.69 MB 372.69 MB\npolonius        2     186.34 MB 372.67 MB\nalacritty       9     39.08 MB  351.74 MB\nosmesa-src      2     166.12 MB 332.24 MB\n````\n#### Do a light cleanup\nThis removes extracted tarball sources and repository checkouts.\nThe original source archives and git repos are kept and will be extracted as needed by cargo.\nRun `cargo cache --autoclean`:\n````\nClearing cache...\n\nCargo cache '/home/matthias/.cargo':\n\nTotal:                                     3.38 GB =\u003e 3.28 GB\n  62 installed binaries:                            665.64 MB\n  Registry:                                2.03 GB =\u003e 2.00 GB\n    2 registry indices:                             444.25 MB\n    10570 crate archives:                             1.55 GB\n    96 =\u003e 0 crate source checkouts:          34.81 MB =\u003e 0  B\n  Git db:                              685.13 MB =\u003e 619.64 MB\n    114 bare git repos:                             619.64 MB\n    7 =\u003e 0 git repo checkouts:               65.48 MB =\u003e 0  B\n\nSize changed 3.38 GB =\u003e 3.28 GB (-100.29 MB, -2.96%)\n````\n\nThe crate also works if you override the default location of the cargo home via\nthe $CARGO_HOME env var!\n\n\nSide note: cargo-cache started as my *learning-by-doing* rust project, if you see something that you find very odd or is in dire need of improvement please let me know and open a ticket!\n\n#### Cleaning the cache on CI\nSometimes it is desired to [cache the $CARGO_HOME in CI](https://doc.rust-lang.org/nightly/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci).\nAs noted in the document, this might cache sources twice which adds unnecessary overhead.\nTo reduce the size of the cache before storing it, you might want to run `cargo cache --autoclean`.\nThe `ci-autoclean` feature provides a very stripped-down version of the crate that is only capable of running `cargo-cache --autoclean` automatically on launch and should compile within a couple of seconds.\nTo make use of this, you can add these commands to your ci:\n````bash\ncargo install (--git git://github.com/matthiaskrgr/cargo-cache OR cargo-cache) --no-default-features --features ci-autoclean cargo-cache\ncargo-cache # no further arguments required\n````\nYou can add the `vendored-libgit` feature if you would like to link libgit statically into cargo-cache.\n\n#### FAQ\nQ: Is this project related to [sccache](https://github.com/mozilla/sccache)?\nA: Not really.\n   `cargo cache sccache` prints a little summary of the local(!) sccache-cache and shows how many files were last accessed on a given date but\n   it does not modify sccaches cache. It also does not act as a compiler cache such as (s)ccache.\n\n\n#### License:\n\nCopyright 2017-2022 Matthias Krüger\n\n````\nLicensed under the Apache License, Version 2.0 \u003cLICENSE-APACHE or\nhttp://www.apache.org/licenses/LICENSE-2.0\u003e or the MIT license\n\u003cLICENSE-MIT or http://opensource.org/licenses/MIT\u003e, at your\noption. All files in the project carrying such notice may not be\ncopied, modified, or distributed except according to those terms.\n````\n","funding_links":[],"categories":["Rust","Development tools"],"sub_categories":["Build system"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthiaskrgr%2Fcargo-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatthiaskrgr%2Fcargo-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthiaskrgr%2Fcargo-cache/lists"}