#async-api #content-addressable #async-std #cache #disk #data #key-value

cacache

Content-addressable, key-value, high-performance, on-disk cache

29 stable releases (13 major)

13.1.0 Nov 26, 2024
13.0.0 Feb 15, 2024
12.0.0 Oct 7, 2023
11.7.1 Sep 11, 2023
0.2.0 Jun 9, 2019

#37 in Filesystem

Download history 9643/week @ 2024-08-14 14241/week @ 2024-08-21 12861/week @ 2024-08-28 10616/week @ 2024-09-04 10968/week @ 2024-09-11 11451/week @ 2024-09-18 12330/week @ 2024-09-25 10778/week @ 2024-10-02 10483/week @ 2024-10-09 12668/week @ 2024-10-16 11714/week @ 2024-10-23 11107/week @ 2024-10-30 9593/week @ 2024-11-06 12477/week @ 2024-11-13 12032/week @ 2024-11-20 9694/week @ 2024-11-27

45,626 downloads per month
Used in 80 crates (20 directly)

Apache-2.0

175KB
3.5K SLoC

cacache CI crates.io

A high-performance, concurrent, content-addressable disk cache, optimized for async APIs.

Example

use cacache;
use async_attributes;

#[async_attributes::main]
async fn main() -> Result<(), cacache::Error> {
    let dir = String::from("./my-cache");

    // Write some data!
    cacache::write(&dir, "key", b"my-async-data").await?;

    // Get the data back!
    let data = cacache::read(&dir, "key").await?;
    assert_eq!(data, b"my-async-data");

    // Clean up the data!
    cacache::rm::all(&dir).await?;
}

Install

Using cargo-edit

$ cargo add cacache

Minimum supported Rust version is 1.43.0.

Documentation

Features

  • First-class async support, using either async-std or tokio as its runtime. Sync APIs are available but secondary. You can also use sync APIs only and remove the async runtime dependency.
  • std::fs-style API
  • Extraction by key or by content address (shasum, etc)
  • Subresource Integrity web standard support
  • Multi-hash support - safely host sha1, sha512, etc, in a single cache
  • Automatic content deduplication
  • Atomic content writes even for large data
  • Fault tolerance (immune to corruption, partial writes, process races, etc)
  • Consistency guarantees on read and write (full data verification)
  • Lockless, high-concurrency cache access
  • Really helpful, contextual error messages
  • Large file support
  • Pretty darn fast
  • Arbitrary metadata storage
  • Cross-platform: Windows and case-(in)sensitive filesystem support
  • miette integration for detailed, helpful error reporting.
  • Punches nazis

async-std is the default async runtime. To use tokio instead, turn off default features and enable the tokio-runtime feature, like this:

[dependencies]
cacache = { version = "*", default-features = false, features = ["tokio-runtime", "mmap"] }

You can also remove async APIs altogether, including removing async runtime dependency:

[dependencies]
cacache = { version = "*", default-features = false, features = ["mmap"] }

Experimental support for symlinking to existing files is provided via the "link_to" feature.

Contributing

The cacache team enthusiastically welcomes contributions and project participation! There's a bunch of things you can do if you want to contribute! The Contributor Guide has all the information you need for everything from reporting bugs to contributing entire new features. Please don't hesitate to jump in if you'd like to, or even ask us questions if something isn't clear.

All participants and maintainers in this project are expected to follow Code of Conduct, and just generally be excellent to each other.

Happy hacking!

MSRV

The Minimum Supported Rust Version for cacache is 1.67.0. Any changes to the MSRV will be considered breaking changes.

License

This project is licensed under the Apache-2.0 License.

Dependencies

~7–37MB
~580K SLoC