Expand description
§bincache
bincache
is a versatile, high-performance, async-first binary data caching library for Rust, designed with a focus on flexibility, efficiency, and ease of use. It enables developers to store, retrieve, and manage binary data using various caching strategies, catering to different storage needs and optimization requirements.
The library offers several caching strategies out of the box:
- Memory: This strategy stores all the data directly in memory. It is ideal for smaller sets of data that need to be accessed frequently and quickly.
- Disk: This strategy saves data exclusively to disk storage. It is best suited for large data sets that don’t need to be accessed as often or as swiftly.
- Hybrid: This strategy is a combination of memory and disk storage. It stores data in memory first, and swaps to disk for files that don’t fit the memory limit.
We also offer opt-in support for data compression:
- zstd: Enabled using the
comp_zstd
feature flag. - more to come…
This crate is intended to be versatile, serving as an efficient solution whether you’re developing a high-load system that needs to reduce database pressure, an application that requires quick access to binary data, or any other situation where efficient caching strategies are vital.
§Usage
Add bincache
to your Cargo.toml
dependencies:
cargo add bincache # for stdlib I/O
cargo add bincache --features rt_tokio_1 # for tokio I/O
cargo add bincache --features rt_async-std_1 # for async-std I/O
§Examples
Getting started quickly using ready-made aliased cache builders:
use bincache::MemoryCacheBuilder;
let mut cache = MemoryCacheBuilder::default().build().await?;
cache.put("key", b"value".to_vec()).await?;
More advanced usage, using the builder directly:
use bincache::{Cache, CacheBuilder, MemoryStrategy};
let mut cache = CacheBuilder::default()
.with_strategy(MemoryStrategy::default())
.build().await?;
cache.put("key", b"value".to_vec()).await?;
§License
bincache is licensed under the MIT license.
Re-exports§
pub use cache_builder::CacheBuilder;
pub use cache_capacity::CacheCapacity;
pub use compression::NO_COMPRESSION;
pub use error::Error;
pub use $crate::strategies::Disk as DiskStrategy;
pub use $crate::strategies::Hybrid as HybridStrategy;
pub use $crate::strategies::Memory as MemoryStrategy;
pub use traits::*;
Modules§
Structs§
- Binary cache.
- A no-op object that implements both
CacheStrategy
andCompressionStrategy
. Can be used as a placeholder in testing, or as a default compression strategy (acts as an identity function).
Type Aliases§
- A Cache using the DiskStrategy.
- A CacheBuilder using the DiskStrategy.
- A Cache using the HybridStrategy.
- A CacheBuilder using the HybridStrategy.
- A Cache using the MemoryStrategy.
- A CacheBuilder using the MemoryStrategy.