initializes a new lru cache of size 2
let mut lru = LruCache::new(2);
lru.put(1, 1);
lru.put(2, 2);
lru.get(1); // Some(1)
Note: keys can be of any type that implements Eq, Clone, and Hash values can be of any type that implements Clone
deletes the item from the cache based on key
lru.delete(1);
clears the lru caches completely
lru.reset();
Run the demo using cargo run
.
You can edit the main.rs
file to play around with the cache itself.