Package org.molgenis.data.cache.l2
Class L2Cache
- java.lang.Object
-
- org.molgenis.data.cache.l2.L2Cache
-
- All Implemented Interfaces:
org.molgenis.data.transaction.TransactionListener
@Service public class L2Cache extends java.lang.Object implements org.molgenis.data.transaction.TransactionListenerIn-memory cache of entities read from cacheable repositories.
-
-
Constructor Summary
Constructors Constructor Description L2Cache(org.molgenis.data.transaction.TransactionManager transactionManager, EntityHydration entityHydration, org.molgenis.data.transaction.TransactionInformation transactionInformation, io.micrometer.core.instrument.MeterRegistry meterRegistry)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterCommitTransaction(java.lang.String transactionId)org.molgenis.data.Entityget(org.molgenis.data.Repository<org.molgenis.data.Entity> repository, java.lang.Object id)Retrieves an entity from the cache or the underlying repository.org.molgenis.data.Entityget(org.molgenis.data.Repository<org.molgenis.data.Entity> repository, java.lang.Object id, org.molgenis.data.Fetch fetch)Retrieves a partial entity from the cache or the underlying repository.java.util.List<org.molgenis.data.Entity>getBatch(org.molgenis.data.Repository<org.molgenis.data.Entity> repository, java.lang.Iterable<java.lang.Object> ids)Retrieves a list of entities from the cache.java.util.List<org.molgenis.data.Entity>getBatch(org.molgenis.data.Repository<org.molgenis.data.Entity> repository, java.lang.Iterable<java.lang.Object> ids, org.molgenis.data.Fetch fetch)Retrieves a list of partial entities from the cache.voidlogStatistics()Logs cumulative cache statistics for all known caches.
-
-
-
Constructor Detail
-
L2Cache
public L2Cache(org.molgenis.data.transaction.TransactionManager transactionManager, EntityHydration entityHydration, org.molgenis.data.transaction.TransactionInformation transactionInformation, io.micrometer.core.instrument.MeterRegistry meterRegistry)
-
-
Method Detail
-
afterCommitTransaction
public void afterCommitTransaction(java.lang.String transactionId)
- Specified by:
afterCommitTransactionin interfaceorg.molgenis.data.transaction.TransactionListener
-
get
public org.molgenis.data.Entity get(org.molgenis.data.Repository<org.molgenis.data.Entity> repository, java.lang.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 org.molgenis.data.Entity get(org.molgenis.data.Repository<org.molgenis.data.Entity> repository, java.lang.Object id, org.molgenis.data.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 java.util.List<org.molgenis.data.Entity> getBatch(org.molgenis.data.Repository<org.molgenis.data.Entity> repository, java.lang.Iterable<java.lang.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:
java.lang.RuntimeException- if the cache failed to load the entities
-
getBatch
public java.util.List<org.molgenis.data.Entity> getBatch(org.molgenis.data.Repository<org.molgenis.data.Entity> repository, java.lang.Iterable<java.lang.Object> ids, org.molgenis.data.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:
java.lang.RuntimeException- if the cache failed to load the entities
-
logStatistics
@Scheduled(fixedRate=60000L) public void logStatistics()
Logs cumulative cache statistics for all known caches.
-
-