Class RepositoryCache<V>


  • public class RepositoryCache<V>
    extends 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

    • Constructor Detail

      • RepositoryCache

        public RepositoryCache​(Function<Map<String,​String>,​V> createCacheEntry,
                               BiConsumer<Map<String,​String>,​V> updateCacheEntry,
                               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​(Function<Map<String,​String>,​V> createCacheEntry,
                               BiConsumer<Map<String,​String>,​V> updateCacheEntry,
                               Consumer<V> deleteCacheEntry,
                               com.google.common.cache.CacheBuilder<Object,​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​(Map<String,​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
      • release

        public RepositoryCache.Entry<V> release​(Map<String,​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​(Map<String,​String> repositoryParameter)
        test if a key is present
        Parameters:
        repositoryParameter - the key
        Returns:
        if an entry exists