CacheEvents
A CacheListener that republishes events as a Flow you can collect.
The bridge from the cache's synchronous, inline callback to idiomatic coroutine consumption:
val events = CacheEvents()
val cache = SemanticCache(embedder, listeners = listOf(events))
scope.launch {
events.events.collect { event -> /* ship it somewhere */}
}Delivery is best-effort and non-blocking: the underlying MutableSharedFlow has a bounded buffer and drops the oldest buffered event when a subscriber cannot keep up, so a slow (or absent) collector can never stall a lookup. This is the right trade-off for telemetry — losing an event under load is fine, adding latency to the request path is not. Size the buffer for your burst with bufferCapacity, or subscribe from a fast consumer that offloads its own work.
Events published before anyone subscribes are dropped (replay = 0): a subscriber sees events from the moment it starts collecting, not the cache's history. Safe to register on more than one cache.
Parameters
how many events to hold for a lagging subscriber before dropping the oldest.
Properties
Functions
Handles one event. Must be fast, thread-safe, and must not throw (thrown errors are dropped).