CacheableFlowResult

data class CacheableFlowResult<TData, TError : Throwable>(val fetchState: FetchState, val error: TError?, val data: TData?) : CacheableResultWithData<TData, TError>

Cacheable flow operations for subscribing to reactive data sources (SSE, WebSockets, etc.) and writing each emission to the cache.

By default, each emission overwrites the previous cached value. If you need to preserve previous emissions (e.g., accumulating a chat history or event log), use scan or runningFold on your flow before passing it to the factory:

flowFactoryOf<MyInput, List<ChatMessage>, Exception>(cache = cache) { input ->
chatWebSocket(input.roomId)
.scan(emptyList()) { acc, message -> acc + message }
}

The cache will then store the full accumulated list as the value for that key. Any other subscriber reading the same cache key (e.g., a different composable) will see the complete accumulated history.

To cap the history size, use takeLast:

.scan(emptyList()) { acc, message -> (acc + message).takeLast(100) }

Constructors

Link copied to clipboard
constructor(fetchState: FetchState, error: TError?, data: TData?)

Properties

Link copied to clipboard

Convenience property to know if your cache already has data. This can be helpful with optimistic updates so that you don't always show a spinner if there is cache information already, but you are doing a fetch operation

Link copied to clipboard
open override val data: TData?
Link copied to clipboard
open override val error: TError?
Link copied to clipboard
open override val fetchState: FetchState