Class L1Cache

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

    @Component
    public class L1Cache
    extends 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 Detail

      • transactionStarted

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

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

        public Optional<CacheHit<org.molgenis.data.Entity>> get​(String entityTypeId,
                                                                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​(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