Crates.io | simple-cache-rs |
lib.rs | simple-cache-rs |
version | 0.4.0 |
source | src |
created_at | 2020-11-30 17:27:50.575701 |
updated_at | 2020-12-05 01:47:14.008437 |
description | A simple rust implementation of HashMap with expiration control. |
homepage | |
repository | https://github.com/calvinbrown085/simple-cache-rs |
max_upload_size | |
id | 318296 |
size | 21,834 |
A simple rust implementation of HashMap with expiration control.
use simple_cache_rs::SimpleCache;
let mut scache: SimpleCache<i32, String> = SimpleCache::new(None);
scache.insert(1, String::from("test"));
println!("{:?}", scache.get(&1));
use simple_cache_rs::SimpleCache;
use std::time::Duration;
use std::thread; // For example purposes only
let timeout = Duration::new(1, 0);
let mut scache: SimpleCache<i32, String> = SimpleCache::new(Some(timeout));
scache.insert(1, String::from("test"));
assert_eq!(Some(String::from("test")), scache.get(&1));
thread::sleep(Duration::new(1, 1)); // For example purposes only
assert_ne!(Some(String::from("test")), scache.get(&1));