cacher_rs

Crates.iocacher_rs
lib.rscacher_rs
version0.0.4
sourcesrc
created_at2022-04-14 10:22:47.139922
updated_at2022-04-19 09:38:59.077046
descriptionmemory cache
homepage
repositoryhttps://github.com/cargo-crates/cacher_rs
max_upload_size
id567415
size18,824
sanmu (wuyuedefeng)

documentation

README

DEPRECATED

please visite https://github.com/cargo-crates/mem_cache

CacherRs  

ci Latest Version downloads

usage

  • sync cacher
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");
  • async cacher
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");

methods

  • [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 exists
  • write(key, value) overwrite cache value and expiration time if cache exists
  • expire(key) make cache value expired if cache exists
  • delete(key) remove cache if cache exists
Commit count: 6

cargo fmt