Package com.axelor.cache
Interface AxelorCache<K,V>
- Type Parameters:
K- the type of keys maintained by this cacheV- the type of mapped values
- All Superinterfaces:
AutoCloseable,Closeable,Iterable<Map.Entry<K,V>>
- All Known Implementing Classes:
AbstractRedissonCache,CaffeineCache,CaffeineLoadingCache,RedissonCache,RedissonCacheNative
Cache interface for wrapping different cache implementations
This interface provides fast and simple operations. For full map capabilities, use asMap().
-
Method Summary
Modifier and TypeMethodDescriptionasMap()Returns a view of the entries stored in this cache as a thread-safe map.default voidcleanUp()Performs any pending maintenance operations needed by the cache.default voidclose()Signals that the cache is no longer in use and releases any resources.longReturns the approximate number of entries in this cache.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.default VReturns the value associated with thekeyin this cache, obtaining that value from themappingFunctionif necessary.Returns a map of the values associated with thekeysin this cache, usingCacheLoaderif defined and if necessary.Returns key-specific lock for this cache.voidinvalidate(K key) Discards any cached value for thekey.voidDiscards all cached values.iterator()Returns an iterator over the entries in this cache.voidAssociates thevaluewith thekey.default voidCopies all of the mappings from the specified map to the cache.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
get
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.- 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
-
get
Returns the value associated with thekeyin this cache, obtaining that value from themappingFunctionif necessary.Note that the
mappingFunctionis called only if there is no cached value after calling the cache loader if defined.- 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
Returns a map of the values associated with thekeysin this cache, usingCacheLoaderif defined and if necessary.- 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
Associates thevaluewith thekey.- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key
-
putAll
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 fromkeytovaluein the specified map.- Parameters:
map- the mappings to be stored in this cache
-
invalidate
Discards any cached value for thekey.- Parameters:
key- the key whose mapping is to be removed from the cache
-
invalidateAll
void invalidateAll()Discards all cached values. -
estimatedSize
long estimatedSize()Returns the approximate number of entries in this cache. The actual count may differ because of concurrent updates and pending invalidations.- Returns:
- the estimated size of the cache
-
asMap
ConcurrentMap<K,V> asMap()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.
- Returns:
- a thread-safe view of this cache supporting
ConcurrentMapoperations
-
iterator
Returns an iterator over the entries in this cache. -
close
default void close()Signals that the cache is no longer in use and releases any resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
cleanUp
default void cleanUp()Performs any pending maintenance operations needed by the cache. Exactly which activities are performed -- if any -- is implementation-dependent. -
getLock
Returns key-specific lock for this cache.- Parameters:
key-- Returns:
- reentrant lock
-