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

Constructors

LRUCache(int capacity)
Creates an LRU cache with the given capacity.

Properties

capacity int
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

get(K key) → V?
Returns the value associated with key if present, and marks the entry as most recently used. Returns null if key is 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 key with value. 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