SingleValueCache<T> class
Simple single-value cache with an optional maxAge expiration time for cached items
Constructors
-
SingleValueCache({Duration? maxAge, Future<
T> provider()?})
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<
T> Function()?) -
If provided, the cache will get the value by using this provider
function when value is called and the value is not cached.
If this is not set, value cannot be called, and getOrFetch must be
used
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
value
→ Future<
T> -
Uses provider to get the value if it is not cached, or returns the
cached value if it was. If provider is not set, this will throw an
exception
no setter
Methods
-
clear(
) → void - Clear the cached value. Calling value or getOrFetch will cause the provider to be run again. Calls which are already in progress and not finished will NOT be cancelled and still receive the value when they complete
-
getOrFetch(
Future< T> provider()) → Future<T> -
Gets or computes the value using the provided
provider
function. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited