Package com.axelor.cache.caffeine
Class CaffeineCache<K,V>
java.lang.Object
com.axelor.cache.caffeine.CaffeineCache<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>>
- Direct Known Subclasses:
CaffeineLoadingCache
Caffeine cache
This wraps a Cache
.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasMap()
Returns a view of the entries stored in this cache as a thread-safe map.void
cleanUp()
Performs any pending maintenance operations needed by the cache.void
close()
Signals that the cache is no longer in use and releases any resources.long
Returns the approximate number of entries in this cache.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
.Returns the value associated with thekey
in this cache, obtaining that value from themappingFunction
if necessary.Returns a map of the values associated with thekeys
in this cache, usingCacheLoader
if defined and if necessary.Returns key-specific lock for this cache.void
invalidate
(K key) Discards any cached value for thekey
.void
Discards all cached values.void
Associates thevalue
with thekey
.void
Copies all of the mappings from the specified map to the cache.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
-
cache
-
locks
-
-
Constructor Details
-
CaffeineCache
-
-
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> - 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
-
get
Description copied from interface:AxelorCache
Returns the value associated with thekey
in this cache, obtaining that value from themappingFunction
if necessary.Note that the
mappingFunction
is called only if there is no cached value after calling the cache loader if defined.- Specified by:
get
in interfaceAxelorCache<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
-
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> - 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
-
put
Description copied from interface:AxelorCache
Associates thevalue
with thekey
.- Specified by:
put
in interfaceAxelorCache<K,
V> - Parameters:
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified key
-
putAll
Description copied from interface:AxelorCache
Copies all of the mappings from the specified map to the cache.The effect of this call is equivalent to that of calling
put(key, value)
on this map once for each mapping fromkey
tovalue
in the specified map.- Specified by:
putAll
in interfaceAxelorCache<K,
V> - Parameters:
map
- the mappings to be stored in this cache
-
invalidate
Description copied from interface:AxelorCache
Discards any cached value for thekey
.- Specified by:
invalidate
in interfaceAxelorCache<K,
V> - Parameters:
key
- the key whose mapping is to be removed from the cache
-
invalidateAll
public void invalidateAll()Description copied from interface:AxelorCache
Discards all cached values.- Specified by:
invalidateAll
in interfaceAxelorCache<K,
V>
-
estimatedSize
public long estimatedSize()Description copied from interface:AxelorCache
Returns the approximate number of entries in this cache. The actual count may differ because of concurrent updates and pending invalidations.- Specified by:
estimatedSize
in interfaceAxelorCache<K,
V> - Returns:
- the estimated size of the cache
-
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> - Returns:
- a thread-safe view of this cache supporting
ConcurrentMap
operations
-
close
public void close()Description copied from interface:AxelorCache
Signals that the cache is no longer in use and releases any resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceAxelorCache<K,
V> - Specified by:
close
in interfaceCloseable
-
cleanUp
public void cleanUp()Description copied from interface:AxelorCache
Performs any pending maintenance operations needed by the cache. Exactly which activities are performed -- if any -- is implementation-dependent.- Specified by:
cleanUp
in interfaceAxelorCache<K,
V>
-
getLock
Description copied from interface:AxelorCache
Returns key-specific lock for this cache.- Specified by:
getLock
in interfaceAxelorCache<K,
V> - Parameters:
key
-- Returns:
- reentrant lock
-