LRUCache<K, V> class

A simple LRU (Least Recently Used) cache with a fixed capacity.

Reads (operator []) and writes (operator []=) both run in O(1) time. When the cache is full, inserting a new entry evicts the least recently used entry.

Note that this is a mutable object: hashCode is computed from the current entries and changes as the cache is modified, so instances are not suitable as keys in a Map or elements in a Set.

Constructors

LRUCache(int capacity)
Creates an LRU cache that holds at most capacity entries.

Properties

capacity → int
The maximum number of entries the cache can hold.
final
hashCode → int
The hash code for this object.
no setteroverride
isEmpty → bool
Whether the cache contains no entries.
no setter
isNotEmpty → bool
Whether the cache contains at least one entry.
no setter
length → int
The number of entries currently in the cache.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
Removes all entries from the cache.
containsKey(K key) → bool
Whether the cache contains an entry for key.
keys() → Iterable<K>
The keys of the cache, ordered from least to most recently used.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(K key) → V?
Removes the entry for key and returns its value, or null if key is not in the cache.
toString() → String
A string representation of this object.
override
values() → Iterable<V>
The values of the cache, ordered from least to most recently used.

Operators

operator ==(Object other) → bool
The equality operator.
override
operator [](K key) → V?
Returns the value for key, or null if key is not in the cache.
operator []=(K key, V value) → void
Associates value with key.