KeyValueCache<K, V> class

A cache implementation that caches values based on keys

maxAge can be used to control how long values remain cached If provider is set, the cache will be filled with values from the provider and [] and get can be used to retrieve values from the cache. If provider is not set, only getOrFetch can be used to retrieve values from the cache.

Constructors

KeyValueCache({Duration? maxAge, Future<V> provider(K key)?})

Properties

hashCode int
The hash code for this object.
no setterinherited
maxAge Duration?
The maximum duration a value will be cached. Null means no expiration.
final
provider → (Future<V> Function(K key)?)
A provider function that takes the key of the value to be provided and returns the value future. If this is set, getOrFetch cannot be used but [] and get can be used
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
Clears all cached values
get(K key) Future<V>
Gets the value for the given key from the cache or uses the provider set in the constructor to calculate (and store) the value.
getOrFetch(K key, Future<V> provider()) Future<V>
Gets or computes the value for the provided key using the provided provider function and store it in the cache using the provided key.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(K key) → void
Remove a single 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>
Convenience operator that delegates to get