Crates.io | cacher_rs |
lib.rs | cacher_rs |
version | 0.0.4 |
source | src |
created_at | 2022-04-14 10:22:47.139922 |
updated_at | 2022-04-19 09:38:59.077046 |
description | memory cache |
homepage | |
repository | https://github.com/cargo-crates/cacher_rs |
max_upload_size | |
id | 567415 |
size | 18,824 |
please visite https://github.com/cargo-crates/mem_cache
use cacher_rs::{Cacher};
let mut i32_cacher = Cacher::<i32>::new();
// expires_in_secs: 0 -> expires immediate
let v1 = i32_cacher.fetch("v1", 10, || 1);
assert_eq!(v1, &1);
let mut string_cacher = Cacher::<String>::new();
let v1 = string_cacher.fetch("v1", 10, || "1".to_string());
assert_eq!(v1, "1");
use cacher_rs::{AsyncCacher};
let mut i32_cacher = AsyncCacher::<i32>::new();
// expires_in_secs: 0 -> expires immediate
let v1 = i32_cacher.fetch("v1", 10, || Box::pin(async {
Ok(1)
})).await?;
assert_eq!(v1, &1);
let mut string_cacher = AsyncCacher::<String>::new();
let v1 = string_cacher.fetch("v1", 10, || Box::pin(async {
Ok("1".to_string())
})).await?;
assert_eq!(v1, "1");
[async] fetch(key, value, closure)
return cache value if not expires or recalculate closure value[async] force_fetch(key, value, closure)
force recalculate closure value[async] read(key)
return key cache value if cache existswrite(key, value)
overwrite cache value and expiration time if cache existsexpire(key)
make cache value expired if cache existsdelete(key)
remove cache if cache exists