CacheableFlowResult
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) }Properties
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