| Crates.io | bincache |
| lib.rs | bincache |
| version | 0.5.1 |
| created_at | 2024-04-29 15:39:04.472494+00 |
| updated_at | 2024-04-29 15:45:46.357688+00 |
| description | ZitaneLabs binary cache. |
| homepage | |
| repository | https://github.com/ZitaneLabs/bincache |
| max_upload_size | |
| id | 1224275 |
| size | 79,615 |
Bincache uses a strategy pattern to allow for different caching strategies:
CacheStrategyBincache supports various compression algorithms:
comp_gzip)comp_brotli)comp_zstd)CompressionStrategyBincache supports multiple async runtimes:
rt_tokio_1)rt_async-std_1)Add bincache to your project:
cargo add bincache # use blocking I/O
cargo add bincache --features rt_tokio_1 # enable tokio 1.x support
cargo add bincache --features rt_async-std_1 # enable async-std 1.x support
Create a Cache instance with your preferred strategy:
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut cache = bincache::MemoryCacheBuilder::default().build().await?;
// Put a key-value pair into the cache
cache.put(&"foo", b"foo".to_vec()).await?;
// Read the value back out
let foo = cache.get(&"foo").await?;
// Make sure it's the same
assert_eq!(foo, b"foo".as_slice());
Ok(())
}
That's it!
blocking - Enables blocking stdlib I/Ort_tokio_1 - Enables tokio 1.x supportrt_async-std_1 - Enables async-std 1.x supportcomp_zstd - Enables zstd compression supportcomp_gzip - Enables gzip compression supportcomp_brotli - Enabled brotli compression supportBy default, we enable a "soft"
implicit-blockingfeature, which only uses blocking I/O if no other runtime feature is enabled.You can explicitly opt-in to blocking I/O by enabling the
blockingfeature, which will disallow the use ofrt_tokio_1andrt_async-std_1.