Repository Cache
The cache of Entity
objects for a certain Repository
and selected identifiers.
Reduces the number of both read and write storage operations in cases if more than one message is dispatched to the target entity. The typical scenario looks like this:
- Several messages are being dispatched to the entity. The framework calls startCaching(entityId) method.
- Before dispatching the first message, the repository loads the entity via the cache; the cache executes the read operation, remembers the result and returns the entity.
- The first message is dispatched to the entity. store(Entity) method is called. Instead of executing the write operation right away, the cache stores the updated entity in its memory.
- More messages are dispatched to the same entity. Each read operation is served by the cache instead of executing the reads from the underlying storage. Upon entity updates, the changed entity is stored into the cache memory.
- The dispatching of the message batch is completed. The framework calls stopCaching(entityId) method. Then the cache pushes the updated entity to the underlying storage by executing the write operation.
The users of this class should keep the number of the simultaneously cached entities reasonable due to a potentially huge significant memory footprint.
Parameters
<I>
the type of Entity
identifiers
<E>
the type of entity
Constructors
Link copied to clipboard
public void RepositoryCache(boolean multitenant, RepositoryCache.Load<I, E> loadFn, RepositoryCache.Store<E> storeFn)
Creates the instance of the cache considering the multi-tenancy setting, the function to load entities and the function to store the entity .