Class L2Cache

  • All Implemented Interfaces:
    org.molgenis.data.transaction.TransactionListener

    @Service
    public class L2Cache
    extends Object
    implements org.molgenis.data.transaction.TransactionListener
    In-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)  
    • 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​(String transactionId)
        Specified by:
        afterCommitTransaction in interface org.molgenis.data.transaction.TransactionListener
      • get

        public org.molgenis.data.Entity get​(org.molgenis.data.Repository<org.molgenis.data.Entity> repository,
                                            Object id)
        Retrieves an entity from the cache or the underlying repository.
        Parameters:
        repository - the underlying repository
        id - 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
      • getBatch

        public List<org.molgenis.data.Entity> getBatch​(org.molgenis.data.Repository<org.molgenis.data.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 cache
        ids - Iterable of 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
      • logStatistics

        @Scheduled(fixedRate=60000L)
        public void logStatistics()
        Logs cumulative cache statistics for all known caches.