Class LruInMemoryStateRebuildingCache
java.lang.Object
com.opencqrs.framework.command.cache.LruInMemoryStateRebuildingCache
- All Implemented Interfaces:
StateRebuildingCache
StateRebuildingCache
implementation backed by a synchronized
LinkedHashMap
with configurable
maximum capacity and LRU semantics.-
Nested Class Summary
Nested classes/interfaces inherited from interface com.opencqrs.framework.command.cache.StateRebuildingCache
StateRebuildingCache.CacheKey<I>, StateRebuildingCache.CacheValue<I>
-
Constructor Summary
ConstructorsConstructorDescriptionLruInMemoryStateRebuildingCache
(int capacity) Configures this with a maximum capacity. -
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
.
-
Constructor Details
-
LruInMemoryStateRebuildingCache
public LruInMemoryStateRebuildingCache(int capacity) Configures this with a maximum capacity.- Parameters:
capacity
- the maximum number ofStateRebuildingCache.CacheValue
s to keep, before discarding exceed entries
-
-
Method Details
-
fetchAndMerge
public <I> StateRebuildingCache.CacheValue<I> fetchAndMerge(StateRebuildingCache.CacheKey<I> key, Function<StateRebuildingCache.CacheValue<I>, StateRebuildingCache.CacheValue<I>> mergeFunction) Description copied from interface:StateRebuildingCache
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.- Specified by:
fetchAndMerge
in interfaceStateRebuildingCache
- 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
-