Expand description
A Least Recently Used (LRU) Cache.
LRUCache<K, V, MAX_SIZE> stores up to MAX_SIZE key-value pairs,
automatically evicting the least recently used entry when the capacity
is exceeded. This makes it useful for caching expensive computations,
I/O results, or any data where temporal locality is expected.
§Example
let mut cache: LRUCache<i32, String, 2> = LRUCache::new();
cache.put(1, "one".to_string());
cache.put(2, "two".to_string());
// Access key 1, making it most recently used
assert_eq!(cache.get(1).map(|v| v.as_str()), Some("one"));
// Insert new key, evicting key 2 (least recently used)
cache.put(3, "three".to_string());
assert!(cache.get(2).is_none()); // evicted
assert!(cache.get(1).is_some());
assert!(cache.get(3).is_some());