Simple local in-memory cache for Rust.
```rust use std::time::Duration; use memory_cache::MemoryCache;
let mut cache = MemoryCache::new();
let key: &'static str = "key"; let value: &'static str = "Hello, World!";
// None
- if the value must be kept forever.
let lifetime = Some(Duration::from_secs(30));
cache.insert(key, value, lifetime);
assert_eq!(cache.get(&key), Some(&value)); ```
```rust use oncecell::sync::Lazy; use std::sync::Mutex; use memorycache::{MemoryCache, cached};
cached! { fn factorial(x: u128) -> u128 = { if x <= 1 { 1 } else { x * factorial(x - 1) } } }
assert_eq!(factorial(21), 51090942171709440000); ```
Constructors:
diff
- MemoryCache::new(full_scan_frequency: Duration) -> Self
+ MemoryCache::new() -> Self
+ MemoryCache::with_full_scan(full_scan_frequency: Duration) -> Self
Renamed Methods:
To look like a HashMap
.
```diff MemoryCache {
fn contains_key(&self, key: &A) -> bool
fn set(&mut self, key: A, value: B, duration: Option
fn insert(&mut self, key: A, value: B, lifetime: Option
fn getorset
} ```
Changed types of parameters/results:
```diff MemoryCache {
} ```