Cache<K, V> class
A generic cache implementation supporting LFU and LRU eviction algorithms.
This cache automatically loads missing values from a backing store using a provided callback function. It supports both Least Frequently Used (LFU) and Least Recently Used (LRU) eviction policies.
Constructors
-
Cache.new({required CacheStorage<
K, CacheEntry< storage, required EvictionAlgorithm algorithm, required int maxSize, required Future<K, V> >V> loader(K key)}) - Creates a new cache instance.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
keys
→ Future<
List< K> > -
Returns all keys currently in the cache.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
size
→ Future<
int> -
Returns the current number of items in the cache.
no setter
-
values
→ Future<
List< V> > -
Returns all values currently in the cache.
no setter
Methods
-
clear(
) → Future< void> - Clears all items from the cache.
-
containsKey(
K key) → Future< bool> - Checks if a key exists in the cache.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
put(
K key, V value) → Future< void> - Stores a value in the cache with the given key (async version with eviction).
-
remove(
K key) → Future< bool> - Removes a value from the cache.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
K key) → Future< V> - Retrieves a value from the cache by key.
-
operator []=(
K key, V value) → void - Stores a value in the cache with the given key.