public class RepositoryCache<V> extends Object
Modifier and Type | Class and Description |
---|---|
static class |
RepositoryCache.Entry<V> |
Constructor and Description |
---|
RepositoryCache(Function<Map<String,String>,V> createCacheEntry,
BiConsumer<Map<String,String>,V> updateCacheEntry,
Consumer<V> deleteCacheEntry)
Simple cache
|
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
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(Map<String,String> repositoryParameter)
test if a key is present
|
RepositoryCache.Entry<V> |
get(Map<String,String> repositoryParameter) |
RepositoryCache.Entry<V> |
lock(Map<String,String> repositoryParameter)
Return the cache entry:
- call
createCacheEntry() if the entry does not exist
- call updateCacheEntry() otherwise |
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
|
public RepositoryCache(Function<Map<String,String>,V> createCacheEntry, BiConsumer<Map<String,String>,V> updateCacheEntry, Consumer<V> deleteCacheEntry)
Only keep the entries alive in cache during executions, calling deleteCacheEntry() when no execution with this map is running
createCacheEntry
- the function used for creating an entryupdateCacheEntry
- called during a get, to ensure the entry is up to datedeleteCacheEntry
- cleanup the entry and remove the resourcespublic RepositoryCache(Function<Map<String,String>,V> createCacheEntry, BiConsumer<Map<String,String>,V> updateCacheEntry, Consumer<V> deleteCacheEntry, com.google.common.cache.CacheBuilder<Object,Object> cacheBuilder)
Keep the entry in a cache constructed by the provided builder at the end of all executions related to this cache entry
createCacheEntry
- the function used for creating an entryupdateCacheEntry
- called during a lock, to ensure the entry is up to datedeleteCacheEntry
- cleanup the entry and remove the resourcescacheBuilder
- will be used for caching entries in-between executionspublic RepositoryCache.Entry<V> lock(Map<String,String> repositoryParameter)
createCacheEntry()
if the entry does not exist
- call updateCacheEntry()
otherwise
The entry will be keep in cache until release()
is called
repositoryParameter
- the parameter associated with the entrypublic RepositoryCache.Entry<V> get(Map<String,String> repositoryParameter)
public RepositoryCache.Entry<V> release(Map<String,String> repositoryParameter)
repositoryParameter:
- the parameter associated with the entryCopyright © 2020. All rights reserved.