CachedCall<T> class

One API read, described but not yet made. The caller decides how it is served each time it is fetched:

final assignments = api.myAssignments();        // a CachedCall
assignments.values();                           // saved copy, then server
assignments.values(CacheStrategy.serverOnly);   // server only
await assignments.server();                     // just the server's answer

An ApiCache makes calls that save every answer; CachedCall.direct makes one with no cache at all (an in-memory fake, say), and the public constructor wraps any other source. A view model consumes one with ViewModel.watch.

Constructors

CachedCall(Stream<Cached<T>> serve(CacheStrategy strategy))
A call served by serve, which must emit at most one local answer and then exactly one server answer (or an error), and honour the strategy it is given.
CachedCall.direct(Future<T> fetch())
A call with no cache: every strategy asks fetch and emits its answer as the server's.
factory
CachedCall.scripted({T local()?, required FutureOr<T> server(), bool same(T local, T server)?})
A call that plays a fixed script, for tests: local (if given) as the saved copy under CacheStrategy.localThenServer, then server. same decides Cached.sameAsLocal; it defaults to ==.
factory

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

fetch([CacheStrategy strategy = CacheStrategy.localThenServer]) → Stream<Cached<T>>
Every answer, with where it came from: under CacheStrategy.localThenServer the saved copy (if any) and then the server's; under CacheStrategy.serverOnly the server's alone.
map<R>(R convert(T value)) → CachedCall<R>
The same call with every answer passed through convert — from the stored shape (raw JSON, say) to the app's models. It runs on every answer, so anything it derives from the clock is fresh each time.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
server() → Future<T>
The server's answer, saved as usual. For code that acts on what it reads and must not see a copy.
toString() → String
A string representation of this object.
inherited
values([CacheStrategy strategy = CacheStrategy.localThenServer]) → Stream<T>
fetch without the wrapping: just the values.

Operators

operator ==(Object other) → bool
The equality operator.
inherited