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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! LRU cache trait and implementations / LRU 缓存 trait 及实现
use Hash;
use LruCache;
/// LRU cache trait providing basic cache operations
///
/// This trait defines the essential operations for a cache implementation:
/// - retrieving values by key
/// - inserting key-value pairs
/// - removing entries by key
///
/// # Type Parameters
/// - `K`: The key type, must implement `Hash` and `Eq` for LRU implementation
/// - `V`: The value type
/// A real LRU (Least Recently Used) cache implementation.
///
/// This cache automatically evicts the least recently used items
/// when the capacity limit is reached. The most recently accessed
/// items are kept in the cache.
///
/// # Type Parameters
/// - `K`: Key type, must implement `Hash` + `Eq`
/// - `V`: Value type
///
/// # Examples
/// ```
/// use jdb_lru::{Cache, Lru};
///
/// let mut cache: Lru<&str, &str> = Lru::new(2);
/// cache.set("key1", "value1");
/// cache.set("key2", "value2");
///
/// assert_eq!(cache.get(&"key1"), Some(&"value1"));
///
/// // Adding a third item evicts the least recently used
/// cache.set("key3", "value3");
/// assert_eq!(cache.get(&"key2"), None); // evicted
/// ```
;
/// A no-op cache implementation with zero overhead.
///
/// This implementation performs no actual caching operations,
/// making it ideal for scenarios where caching is disabled
/// or for garbage collection friendly code paths.
///
/// All operations are no-ops and `get()` always returns `None`.
/// This provides a consistent interface while eliminating any
/// allocation or storage overhead.
///
/// # Examples
///
/// ```ignore
/// use jdb_lru::{Cache, NoCache};
///
/// let mut cache: NoCache = NoCache;
///
/// // All operations are no-ops
/// cache.set("key", "value");
/// cache.rm(&"key"); // also a no-op
/// // No matter what you do, get() always returns None
/// ```
;