5 releases

Uses new Rust 2021

0.0.4 Apr 19, 2022
0.0.3 Apr 19, 2022
0.0.2 Apr 15, 2022
0.0.1 Apr 14, 2022
0.0.0 Apr 14, 2022

#40 in Caching

Download history 106/week @ 2022-04-14 16/week @ 2022-04-21 15/week @ 2022-04-28 35/week @ 2022-05-05 81/week @ 2022-05-12 21/week @ 2022-05-19 15/week @ 2022-05-26 51/week @ 2022-06-02 2/week @ 2022-06-16

73 downloads per month

MIT/Apache

18KB
433 lines

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

Dependencies

~125KB