Package org.molgenis.data.cache.l2
Class L2Cache
- java.lang.Object
-
- org.molgenis.data.cache.l2.L2Cache
-
- All Implemented Interfaces:
TransactionListener
@Service public class L2Cache extends Object implements TransactionListener
In-memory cache of entities read from cacheable repositories.
-
-
Constructor Summary
Constructors Constructor Description L2Cache(TransactionManager transactionManager, EntityHydration entityHydration, TransactionInformation transactionInformation, io.micrometer.core.instrument.MeterRegistry meterRegistry)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterCommitTransaction(String transactionId)Entityget(Repository<Entity> repository, Object id)Retrieves an entity from the cache or the underlying repository.Entityget(Repository<Entity> repository, Object id, Fetch fetch)Retrieves a partial entity from the cache or the underlying repository.List<Entity>getBatch(Repository<Entity> repository, Iterable<Object> ids)Retrieves a list of entities from the cache.List<Entity>getBatch(Repository<Entity> repository, Iterable<Object> ids, Fetch fetch)Retrieves a list of partial entities from the cache.voidlogStatistics()Logs cumulative cache statistics for all known caches.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.molgenis.data.transaction.TransactionListener
commitTransaction, doCleanupAfterCompletion, rollbackTransaction, transactionStarted
-
-
-
-
Constructor Detail
-
L2Cache
public L2Cache(TransactionManager transactionManager, EntityHydration entityHydration, TransactionInformation transactionInformation, io.micrometer.core.instrument.MeterRegistry meterRegistry)
-
-
Method Detail
-
afterCommitTransaction
public void afterCommitTransaction(String transactionId)
- Specified by:
afterCommitTransactionin interfaceTransactionListener
-
get
public Entity get(Repository<Entity> repository, Object id)
Retrieves an entity from the cache or the underlying repository.- Parameters:
repository- the underlying repositoryid- the ID of the entity to retrieve- Returns:
- the retrieved Entity, or null if the entity is not present.
- Throws:
com.google.common.util.concurrent.UncheckedExecutionException- if the repository throws an error when loading the entity
-
get
public Entity get(Repository<Entity> repository, Object id, Fetch fetch)
Retrieves a partial entity from the cache or the underlying repository.- Parameters:
repository- the underlying repositoryid- the ID of the entity to retrievefetch- containing attributes to retrieve, can be null- Returns:
- the retrieved Entity, or null if the entity is not present.
- Throws:
com.google.common.util.concurrent.UncheckedExecutionException- if the repository throws an error when loading the entity
-
getBatch
public List<Entity> getBatch(Repository<Entity> repository, Iterable<Object> ids)
Retrieves a list of entities from the cache. If the cache doesn't yet exist, will create the cache.- Parameters:
repository- the underlying repository, used to create the cache loader or to retrieve the existing cacheids-Iterableof the ids of the entities to retrieve- Returns:
- List containing the retrieved entities, missing values are excluded
- Throws:
RuntimeException- if the cache failed to load the entities
-
getBatch
public List<Entity> getBatch(Repository<Entity> repository, Iterable<Object> ids, Fetch fetch)
Retrieves a list of partial entities from the cache. If the cache doesn't yet exist, will create the cache.- Parameters:
repository- the underlying repository, used to create the cache loader or to retrieve the existing cacheids-Iterableof the ids of the entities to retrievefetch- containing attributes to retrieve, can be null- Returns:
- List containing the retrieved entities, missing values are excluded
- Throws:
RuntimeException- if the cache failed to load the entities
-
logStatistics
@Scheduled(fixedRate=60000L) public void logStatistics()
Logs cumulative cache statistics for all known caches.
-
-