Interface StateRebuildingCache
- All Known Implementing Classes:
LruInMemoryStateRebuildingCache
,NoStateRebuildingCache
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Interface specifying operations to cache event-sourced
instance state to reduce the number of fetched events prior to executing a
CommandHandler
.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final record
Represents the cache key, whoseequality
determines, whichStateRebuildingCache.CacheValue
to fetch.static final record
Represents the cache value. -
Method Summary
Modifier and TypeMethodDescriptionfetchAndMerge
(StateRebuildingCache.CacheKey<I> key, Function<StateRebuildingCache.CacheValue<I>, StateRebuildingCache.CacheValue<I>> mergeFunction) Method supposed to fetch aStateRebuildingCache.CacheValue
from the underlying cache based on the givenStateRebuildingCache.CacheKey
.
-
Method Details
-
fetchAndMerge
<I> StateRebuildingCache.CacheValue<I> fetchAndMerge(StateRebuildingCache.CacheKey<I> key, Function<StateRebuildingCache.CacheValue<I>, StateRebuildingCache.CacheValue<I>> mergeFunction) Method supposed to fetch aStateRebuildingCache.CacheValue
from the underlying cache based on the givenStateRebuildingCache.CacheKey
. The cached value is applied to the givenmergeFunction
, the underlying cache updated with the mergedStateRebuildingCache.CacheValue
, before it is returned to the caller. Implementations may choose to return an even newerStateRebuildingCache.CacheValue
, if concurrent merges occur.- Type Parameters:
I
- the generic instance type being cached- Parameters:
key
- the cache keymergeFunction
- a merge function updating aStateRebuildingCache.CacheValue
previously cached, typically by fetching newer events, applying them to the instance and returning the merged value, which will then be applied to the underlying cache (if no newer value has already been applied concurrently, depending on the concurrency guarantees of the implementation). In case of a cache miss, aStateRebuildingCache.CacheValue
withnull
contents will be passed to the merge function, as annotated.- Returns:
- the fetched and merged cache value
-