Crates.io | r-cache |
lib.rs | r-cache |
version | 0.5.0 |
source | src |
created_at | 2020-09-19 19:37:42.215685 |
updated_at | 2023-02-18 10:59:17.611544 |
description | r-cache is an in memory key value store. It is thread safe and values have expiry times |
homepage | |
repository | https://github.com/cobbinma/r-cache |
max_upload_size | |
id | 290482 |
size | 12,858 |
r-cache is an in memory key value store. It is thread safe and values can have expiry times.
use async_std::sync::Arc;
use async_std::task;
use r_cache::cache::Cache;
use std::time::Duration;
const KEY: i8 = 0;
const VALUE: &str = "VALUE";
#[async_std::main]
async fn main() {
let cache = Arc::new(Cache::new(Some(Duration::from_secs(5 * 60))));
task::spawn({
let cache = Arc::clone(&cache);
async move {
loop {
task::sleep(Duration::from_secs(10 * 60)).await;
cache.remove_expired();
}
}
});
cache.set(KEY, VALUE, None);
assert_eq!(VALUE, cache.get(&KEY).unwrap())
}