KeyedReplica

interface KeyedReplica<K : Any, out T : Any>

Keyed replica replicates multiple chunks of data - different chunks for different keys.

The difference between KeyedReplica and KeyedPhysicalReplica is that the latter has a richer API. KeyedReplica has minimalistic read-only API, whereas KeyedPhysicalReplica allows to cancel requests, modify data, execute optimistic updates.

Functions

Link copied to clipboard
abstract suspend fun getData(key: K, forceRefresh: Boolean = false): T

Loads and returns data for a given key. Throws an exception on error. It never returns stale data. It makes a network request if data is stale.

Link copied to clipboard
abstract fun observe(    observerCoroutineScope: CoroutineScope,     observerActive: StateFlow<Boolean>,     key: StateFlow<K?>): ReplicaObserver<T>

Starts to observe a keyed replica. Returned ReplicaObserver gives access to replica state and error events.

Link copied to clipboard
abstract fun refresh(key: K)

Loads fresh data from a network for a given key.

Link copied to clipboard
abstract fun revalidate(key: K)

Loads fresh data from a network for a given key if it is stale.

Inheritors

Link copied to clipboard

Extensions

Link copied to clipboard
fun <K : Any, T : Any> KeyedReplica<K, T>.keepPreviousData(): KeyedReplica<K, T>

Modifies KeyedReplica so its observer keeps a data from a previous key until a data for a new key will not be loaded. It allows to dramatically improve UX when KeyedReplica is observed by changing keys.