The type of the keys stored in the cache
The type of the values stored in the cache
Creates a new instance of the LRU Cache.
Configuration options for the LRU Cache
The maximum number of items the cache can hold. Must be a non-negative integer.
Gets the number of items currently stored in the cache.
The total number of cached items.
Removes all key-value entries from the cache.
void
Removes the specified key and its associated value from the cache.
The key to remove from the cache
True if the element was successfully removed, false if the key was not found
Checks if a key exists in the cache
The key to check for existence
true if the key exists in the cache, false otherwise
A Least Recently Used (LRU) cache implementation. Keeps track of how recently entries were accessed and removes the least recently used entry when cache exceeds maxSize.
Example
Illustration of the design:
removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added
Architecture Diagram: LRUCache
┌───────────────────────────────────────────────┐ │ LRUCache │ ├───────────────────────────────────────────────┤ │ #cache: Map<K, V> │ │ #maxSize: number │ └───────────────────────────────────────────────┘ │ ▼ ┌───────────────────────────────┐ │ Map<K, V> │ └───────────────────────────────┘