Crates.io | endorphin |
lib.rs | endorphin |
version | 0.1.9 |
source | src |
created_at | 2021-12-23 09:24:34.595521 |
updated_at | 2022-01-07 09:27:34.288191 |
description | Key-Value based in-memory cache library which supports Custom Expiration Policies |
homepage | |
repository | https://github.com/ArtBlnd/endorphin |
max_upload_size | |
id | 502130 |
size | 99,120 |
Key-Value based in-memory cache library which supports Custom Expiration Policies with standard HashMap, HashSet interface.
use std::thread::sleep;
use std::time::Duration;
use endorphin::policy::TTLPolicy;
use endorphin::HashMap;
fn main() {
let mut cache = HashMap::new(TTLPolicy::new());
cache.insert("Still", "Alive", Duration::from_secs(3));
cache.insert("Gonna", "Die", Duration::from_secs(1));
sleep(Duration::from_secs(1));
assert_eq!(cache.get(&"Still"), Some(&"Alive"));
assert_eq!(cache.get(&"Gonna"), None);
}
Currently, we are providing four pre-defined policies.
LazyFixedTTLPolicy
uses Lazy Expiration as other cache crates do, it expires items when you access entry after its TTL.TTLPolicy
uses Active Expiration which expires even you don't access to expired entries.TTIPolicy
uses Active Expiration which expires even you don't access to expired entries.MixedPolicy
is mixed policy of TTL and TTI