#sync #cache #read #content-addressable #write #read-write #cacache

cacache-sync

Synchronous, content-addressable, key-value, high-performance, on-disk cache

1 stable release

11.0.0 Jan 24, 2023

#216 in Caching

Apache-2.0

48KB
943 lines

cacache-sync CI crates.io

A high-performance, concurrent, content-addressable disk cache, with only sync APIs.

Notes

This is a fork of the cacache crate here: https://github.com/zkat/cacache-rs, which removes all async code and dependencies, and makes the sync APIs the primary usage (no need for _sync suffixes).

The motivation is pretty simple -- in another project I was using cacache, where I only relied on the sync API. I seem to still be paying the cost of having async-related dependencies, so this fork is mostly for people who are definitely only going to be using the sync APIs. I'm not sure how translatable these savings are across other projects, but compile times for debug builds dropped by ~33%.

This fork is likely going to be minimally supported -- I don't see much needing to change about the sync implementations here. If you want to see changes here, you should probably push those to the original project (and consider supporting it as well).

Example

use cacache_sync;

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

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

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

    // Clean up the data!
    cacache_sync::clear(&dir)?;
}

Install

Using cargo-edit

$ cargo add cacache-sync

Minimum supported Rust version is 1.66.1.

Documentation

Features

  • Sync APIs are the primary API.
  • 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)
  • Really helpful, contextual error messages
  • Large file support
  • Pretty darn fast
  • Arbitrary metadata storage
  • Cross-platform: Windows and case-(in)sensitive filesystem support
  • Punches nazis

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!

License

This project is licensed under the Apache-2.0 License.

Dependencies

~3–12MB
~161K SLoC