Class L1Cache

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

    @Component
    public class L1Cache
    extends java.lang.Object
    implements org.molgenis.data.transaction.TransactionListener
    Caches entities within a transaction to speed up queries within those transactions. Each transaction has its own cache. When the transaction is committed the cache is removed.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void doCleanupAfterCompletion​(java.lang.String transactionId)  
      java.util.Optional<CacheHit<org.molgenis.data.Entity>> get​(java.lang.String entityTypeId, java.lang.Object id, org.molgenis.data.meta.model.EntityType entityType)
      Retrieves an entity from the L1 cache based on a combination of entity name and entity id.
      void put​(java.lang.String entityTypeId, org.molgenis.data.Entity entity)
      Puts an entity into the L1 cache, if the cache exists for the current thread.
      void transactionStarted​(java.lang.String transactionId)  
      • 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

        afterCommitTransaction, commitTransaction, rollbackTransaction
    • Method Detail

      • transactionStarted

        public void transactionStarted​(java.lang.String transactionId)
        Specified by:
        transactionStarted in interface org.molgenis.data.transaction.TransactionListener
      • doCleanupAfterCompletion

        public void doCleanupAfterCompletion​(java.lang.String transactionId)
        Specified by:
        doCleanupAfterCompletion in interface org.molgenis.data.transaction.TransactionListener
      • get

        public java.util.Optional<CacheHit<org.molgenis.data.Entity>> get​(java.lang.String entityTypeId,
                                                                          java.lang.Object id,
                                                                          org.molgenis.data.meta.model.EntityType entityType)
        Retrieves an entity from the L1 cache based on a combination of entity name and entity id.
        Parameters:
        entityTypeId - name of the entity to retrieve
        id - id value of the entity to retrieve
        Returns:
        an Optional of which the CacheHit contains an Entity or is empty if deletion of this entity is stored in the cache, or Optional.empty() if there's no information available about this entity in the cache
      • put

        public void put​(java.lang.String entityTypeId,
                        org.molgenis.data.Entity entity)
        Puts an entity into the L1 cache, if the cache exists for the current thread.
        Parameters:
        entityTypeId - name of the entity to put into the cache
        entity - the entity to put into the cache