Package com.axelor.cache.caffeine
Class CaffeineLoadingCache<K,V>
java.lang.Object
com.axelor.cache.caffeine.CaffeineCache<K,V>
com.axelor.cache.caffeine.CaffeineLoadingCache<K,V>
- Type Parameters:
K- the type of keys maintained by this cacheV- the type of mapped values
- All Implemented Interfaces:
AxelorCache<K,,V> Closeable,AutoCloseable,Iterable<Map.Entry<K,V>>
Caffeine loading cache
This wraps a LoadingCache.
In order to match with Redisson behavior, cache loader is always used (normally, Caffeine's get(key, mappingFunction) and asMap() operations skip cache loader).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CacheLoader<? super K, V> protected final ConcurrentMap<K, V> Fields inherited from class com.axelor.cache.caffeine.CaffeineCache
cache, locks -
Constructor Summary
ConstructorsConstructorDescriptionCaffeineLoadingCache(com.github.benmanes.caffeine.cache.LoadingCache<K, V> cache, CacheLoader<? super K, V> loader) -
Method Summary
Modifier and TypeMethodDescriptionasMap()Returns a view of the entries stored in this cache as a thread-safe map.Returns the value associated with thekeyin this cache, obtaining that value from theCacheLoaderif defined and if necessary, otherwise returnsnullif there is no cached value for thekey.Try cache loader before mapping function for consistency with Redisson.Returns a map of the values associated with thekeysin this cache, usingCacheLoaderif defined and if necessary.Methods inherited from class com.axelor.cache.caffeine.CaffeineCache
cleanUp, close, estimatedSize, getLock, invalidate, invalidateAll, put, putAllMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.axelor.cache.AxelorCache
iteratorMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
map
-
loader
-
-
Constructor Details
-
CaffeineLoadingCache
public CaffeineLoadingCache(com.github.benmanes.caffeine.cache.LoadingCache<K, V> cache, CacheLoader<? super K, V> loader)
-
-
Method Details
-
get
Description copied from interface:AxelorCacheReturns the value associated with thekeyin this cache, obtaining that value from theCacheLoaderif defined and if necessary, otherwise returnsnullif there is no cached value for thekey.- Specified by:
getin interfaceAxelorCache<K,V> - Overrides:
getin classCaffeineCache<K,V> - Parameters:
key- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
nullif this map contains no mapping for the key
-
getAll
Description copied from interface:AxelorCacheReturns a map of the values associated with thekeysin this cache, usingCacheLoaderif defined and if necessary.- Specified by:
getAllin interfaceAxelorCache<K,V> - Overrides:
getAllin classCaffeineCache<K,V> - Parameters:
keys- the keys whose associated values are to be returned- Returns:
- an unmodifiable mapping of keys to values for the specified keys in this cache
-
get
Try cache loader before mapping function for consistency with Redisson.- Specified by:
getin interfaceAxelorCache<K,V> - Overrides:
getin classCaffeineCache<K,V> - Parameters:
key- the key with which the specified value is to be associatedmappingFunction- the function to compute a value- Returns:
- the current (existing or computed) value associated with the specified key, or null if the computed value is null
-
asMap
Description copied from interface:AxelorCacheReturns a view of the entries stored in this cache as a thread-safe map. Modifications made to the map directly affect the cache.Note that if the cache has a cache loader, it will be used. This differs from Caffeine's Cache#asMap() and is designed to match Redisson RMap behavior.
- Specified by:
asMapin interfaceAxelorCache<K,V> - Overrides:
asMapin classCaffeineCache<K,V> - Returns:
- a thread-safe view of this cache supporting
ConcurrentMapoperations
-