AggregateServiceCaching

class AggregateServiceCaching<STATE : AggregateState, COMMAND, EVENT>(aggregateStore: AggregateRepository<STATE, COMMAND, EVENT>, cachePolicy: AggregateCachePolicy, aggregateMutexStripes: Int = cachePolicy.aggregateMutexStripes, cacheMutexStripes: Int = 16) : AggregateService<STATE, COMMAND, EVENT> (source)

AggregateService that retains loaded aggregate instances in memory between commands.

Another instance appending to a cached stream leaves the cached state stale. A decision that appends meets the store's expected-version check, conflicts and is evicted. One that does not append never meets the store, so with AggregateCachePolicy.confirmUnwritten a result decided on a cached aggregate is confirmed against the stream tail under the aggregate's stripe and, when the stream has moved on, decided once more on a fresh load. A result decided on a fresh load stands, as it would from AggregateServiceReloading.

Constructors

Link copied to clipboard
constructor(aggregateStore: AggregateRepository<STATE, COMMAND, EVENT>, cachePolicy: AggregateCachePolicy, aggregateMutexStripes: Int = cachePolicy.aggregateMutexStripes, cacheMutexStripes: Int = 16)

Functions

Link copied to clipboard
open suspend override fun getById(id: String): AggregateLookupResult<STATE>
Link copied to clipboard
open suspend override fun handle(command: CommandEnvelope<COMMAND>): AggregateChangeResult<STATE, EVENT>
Link copied to clipboard
open suspend override fun recoverAppend(preparedAppend: PreparedAppend<EVENT>): AggregateRecoveryResult<STATE, COMMAND, EVENT>

Recovers an append returned by AggregateChangeResult.Failure.OutcomeUnknown without handling the original command again. The exact preparedAppend is resubmitted so the store can recognize an existing commit or safely commit the same prepared events, after which aggregate state is reloaded from committed history.