Class RepositoryCache<V>


  • public class RepositoryCache<V>
    extends java.lang.Object
    This cache associates a unique entry to a defined set of repository's parameters This allows to track resources associated to a run

    This cache is based on: - An HashMap, that keep in cache the entries currently used by at least one execution - An optional com.google.common.cache.LoadingCache that keep track of the entries currently not used

    The constructor allows callbacks to create, update or delete the resources and manage the LoadingCache

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  RepositoryCache.Entry<V>  
    • Constructor Summary

      Constructors 
      Constructor Description
      RepositoryCache​(java.util.function.Function<java.util.Map<java.lang.String,​java.lang.String>,​V> createCacheEntry, java.util.function.BiConsumer<java.util.Map<java.lang.String,​java.lang.String>,​V> updateCacheEntry, java.util.function.Consumer<V> deleteCacheEntry)
      Simple cache
      RepositoryCache​(java.util.function.Function<java.util.Map<java.lang.String,​java.lang.String>,​V> createCacheEntry, java.util.function.BiConsumer<java.util.Map<java.lang.String,​java.lang.String>,​V> updateCacheEntry, java.util.function.Consumer<V> deleteCacheEntry, com.google.common.cache.CacheBuilder<java.lang.Object,​java.lang.Object> cacheBuilder)
      With external cache for longer term caching
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean containsKey​(java.util.Map<java.lang.String,​java.lang.String> repositoryParameter)
      test if a key is present
      RepositoryCache.Entry<V> get​(java.util.Map<java.lang.String,​java.lang.String> repositoryParameter)  
      RepositoryCache.Entry<V> lock​(java.util.Map<java.lang.String,​java.lang.String> repositoryParameter)
      Return the cache entry: - call createCacheEntry() if the entry does not exist - call updateCacheEntry() otherwise
      RepositoryCache.Entry<V> release​(java.util.Map<java.lang.String,​java.lang.String> repositoryParameter)
      Decrease the corresponding cache entry's usage and put it in the long term cache if needed
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RepositoryCache

        public RepositoryCache​(java.util.function.Function<java.util.Map<java.lang.String,​java.lang.String>,​V> createCacheEntry,
                               java.util.function.BiConsumer<java.util.Map<java.lang.String,​java.lang.String>,​V> updateCacheEntry,
                               java.util.function.Consumer<V> deleteCacheEntry)
        Simple cache

        Only keep the entries alive in cache during executions, calling deleteCacheEntry() when no execution with this map is running

        Parameters:
        createCacheEntry - the function used for creating an entry
        updateCacheEntry - called during a get, to ensure the entry is up to date
        deleteCacheEntry - cleanup the entry and remove the resources
      • RepositoryCache

        public RepositoryCache​(java.util.function.Function<java.util.Map<java.lang.String,​java.lang.String>,​V> createCacheEntry,
                               java.util.function.BiConsumer<java.util.Map<java.lang.String,​java.lang.String>,​V> updateCacheEntry,
                               java.util.function.Consumer<V> deleteCacheEntry,
                               com.google.common.cache.CacheBuilder<java.lang.Object,​java.lang.Object> cacheBuilder)
        With external cache for longer term caching

        Keep the entry in a cache constructed by the provided builder at the end of all executions related to this cache entry

        Parameters:
        createCacheEntry - the function used for creating an entry
        updateCacheEntry - called during a lock, to ensure the entry is up to date
        deleteCacheEntry - cleanup the entry and remove the resources
        cacheBuilder - will be used for caching entries in-between executions
    • Method Detail

      • lock

        public RepositoryCache.Entry<V> lock​(java.util.Map<java.lang.String,​java.lang.String> repositoryParameter)
        Return the cache entry: - call createCacheEntry() if the entry does not exist - call updateCacheEntry() otherwise

        The entry will be keep in cache until release() is called

        Parameters:
        repositoryParameter - the parameter associated with the entry
        Returns:
        the cache entry
      • get

        public RepositoryCache.Entry<V> get​(java.util.Map<java.lang.String,​java.lang.String> repositoryParameter)
      • release

        public RepositoryCache.Entry<V> release​(java.util.Map<java.lang.String,​java.lang.String> repositoryParameter)
        Decrease the corresponding cache entry's usage and put it in the long term cache if needed
        Parameters:
        repositoryParameter - : the parameter associated with the entry
        Returns:
        The entry, null if it is not in the cache
      • containsKey

        public boolean containsKey​(java.util.Map<java.lang.String,​java.lang.String> repositoryParameter)
        test if a key is present
        Parameters:
        repositoryParameter - the key
        Returns:
        if an entry exists