AsyncCache<T> class Null safety

Runs asynchronous functions and caches the result for a period of time.

This class exists to cover the pattern of having potentially expensive code such as file I/O, network access, or isolate computation that's unlikely to change quickly run fewer times. For example:

final _usersCache = new AsyncCache<List<String>>(const Duration(hours: 1));

/// Uses the cache if it exists, otherwise calls the closure:
Future<List<String>> get onlineUsers => _usersCache.fetch(() {
  // Actually fetch online users here.

This class's timing can be mocked using fake_async.


AsyncCache(Duration _duration)
Creates a cache that invalidates its contents after duration has passed. [...]
Creates a cache that invalidates after an in-flight request is complete. [...]


hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


fetch(Future<T> callback()) Future<T>
Returns a cached value from a previous call to fetch, or runs callback to compute a new one. [...]
fetchStream(Stream<T> callback()) Stream<T>
Returns a cached stream from a previous call to fetchStream, or runs callback to compute a new stream. [...]
invalidate() → void
Removes any cached value.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toString() String
A string representation of this object. [...]


operator ==(Object other) bool
The equality operator. [...]