1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! This crate provides concurrent-safe typedcache with expiration capabilities.
//!
//! ## Usage
//!
//! Add this to your `Cargo.toml`:
//!
//! ```toml
//! [build-dependencies]
//! typedcache = "0.2"
//! ```
//!
//! ## Example
//! ```rust
//! use std::time::Duration;
//!
//! use typedcache::typed::TypedMap;
//!
//! #[tokio::main]
//! async fn main() {
//! let cache = typedcache::cache("test".into());
//! cache
//! .add(
//! TestKey("key_erpired_after_1s".into()),
//! Duration::from_secs(1),
//! TestValue(1),
//! );
//! tokio::time::sleep(Duration::from_secs(2)).await;
//! assert!(cache
//! .get(&TestKey("key_erpired_after_1s".into()))
//! .is_none());
//! }
//!
//! #[derive(Debug, Clone, Eq, PartialEq, Hash)]
//! pub struct TestKey(String);
//!
//! impl TypedMap for TestKey {
//! type Value = TestValue;
//! }
//!
//! pub struct TestValue(isize);
//! ```
//!
use HashMap;
use RwLock;
use crateCacheTable;
lazy_static!
/// Cache returns the existing cache table with given name or creates a new one
/// if the table does not exist yet.