LRUCache<K, V> class
A generic implementation of an LRU (Least Recently Used) Cache.
The cache holds a limited number of key-value pairs up to capacity. When the capacity is reached, the least recently accessed item is evicted.
Uses a LinkedHashMap to maintain insertion order and update on access.
Example:
final cache = LRUCache<String, int>(3);
cache.put('a', 1);
cache.put('b', 2);
cache.get('a'); // Access 'a' to make it most recently used
cache.put('c', 3);
cache.put('d', 4); // This will evict 'b' as least recently used
Properties
Methods
-
get(
K key) → V? -
Returns the value associated with
keyif present, and marks the entry as most recently used. Returnsnullifkeyis not found. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
printCache(
) → void - Prints the current cache content (for debugging).
-
put(
K key, V value) → void -
Inserts or updates the
keywithvalue. If the cache exceeds capacity, evicts the least recently used entry. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited