Crates.io | ded |
lib.rs | ded |
version | 0.1.0 |
source | src |
created_at | 2023-04-29 20:17:25.017668 |
updated_at | 2023-04-29 20:17:25.017668 |
description | Dead Easy Deduplication. |
homepage | |
repository | https://github.com/broxus/ded |
max_upload_size | |
id | 852281 |
size | 29,876 |
Dead Easy Deduplication
ded
is a library which performs request coalescing and caching backed
by schnellru.
[dependencies]
ded = "0.1.0"
let cache = DedCache::new(Duration::from_secs(1), 1024);
let key = "key";
async fn value_fut() -> Result<&'static str, Infallible> {
tokio::time::sleep(Duration::from_secs(2)).await;
Ok("value")
}
// Accessing a new value
let value = cache.get_or_update(key, value_fut).await?;
assert_eq!(value, "value"); // value is returned, request is performed
// Accessing a cached value
{
let start = std::time::Instant::now();
let value = cache.get_or_update(key, value_fut).await?;
assert_eq!(value, "value");
// Value was returned immediately
assert!(start.elapsed() < Duration::from_secs(1));
}
We welcome contributions to the project! If you notice any issues or errors, feel free to open an issue or submit a pull request.
Licensed under either of
at your option.