LRUCache<K, V> class

A generic Least Recently Used (LRU) cache implementation.

Wraps a LinkedHashMap to provide O(1) access and insertion while maintaining insertion order. When the cache exceeds maxSize, the least recently used item (the first item in the iteration order) is evicted.

Constructors

LRUCache(int maxSize)
Creates an LRUCache with the specified maxSize.

Properties

entries List<MapEntry<K, V>>
Returns entries as a List.
no setter
hashCode int
The hash code for this object.
no setterinherited
keys Iterable<K>
Returns iterable of keys in order from least recently used to most recently used.
no setter
length int
Returns the number of entries in the cache.
no setter
maxSize int
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
values Iterable<V>
Returns iterable of values in order from least recently used to most recently used.
no setter

Methods

clear() → void
Removes all entries from the cache.
containsKey(K key) bool
Checks if the cache contains key.
get(K key) → V?
Retrieves the value associated with key, or null if the key is not present.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(K key, V value) → void
Associates the key with the given value.
remove(K key) → V?
Removes the value associated with key and returns it.
removeWhere(bool predicate(K key, V value)) → void
Removes entries that satisfy the given predicate.
toMap() Map<K, V>
Returns a map representation of the cache.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](K key) → V?
Access using [] operator (updates recentness)
operator []=(K key, V value) → void
Sets value using []= operator