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 thekey
in this cache, obtaining that value from theCacheLoader
if defined and if necessary, otherwise returnsnull
if 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 thekeys
in this cache, usingCacheLoader
if defined and if necessary.Methods inherited from class com.axelor.cache.caffeine.CaffeineCache
cleanUp, close, estimatedSize, getLock, invalidate, invalidateAll, put, putAll
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.axelor.cache.AxelorCache
iterator
Methods 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:AxelorCache
Returns the value associated with thekey
in this cache, obtaining that value from theCacheLoader
if defined and if necessary, otherwise returnsnull
if there is no cached value for thekey
.- Specified by:
get
in interfaceAxelorCache<K,
V> - Overrides:
get
in 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
null
if this map contains no mapping for the key
-
getAll
Description copied from interface:AxelorCache
Returns a map of the values associated with thekeys
in this cache, usingCacheLoader
if defined and if necessary.- Specified by:
getAll
in interfaceAxelorCache<K,
V> - Overrides:
getAll
in 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:
get
in interfaceAxelorCache<K,
V> - Overrides:
get
in 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:AxelorCache
Returns 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:
asMap
in interfaceAxelorCache<K,
V> - Overrides:
asMap
in classCaffeineCache<K,
V> - Returns:
- a thread-safe view of this cache supporting
ConcurrentMap
operations
-