Package com.axelor.cache
Class CacheBuilder<K,V>
java.lang.Object
com.axelor.cache.CacheBuilder<K,V>
- Type Parameters:
K- the type of keys maintained by this cacheV- the type of mapped values
- Direct Known Subclasses:
AbstractRedissonCacheBuilder,CaffeineCacheBuilder
A builder of
AxelorCache instances-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCacheBuilder(CacheBuilder<K, V> builder) protectedCacheBuilder(String cacheName) -
Method Summary
Modifier and TypeMethodDescriptionabstract <K1 extends K,V1 extends V>
AxelorCache<K1, V1> build()Builds anAxelorCachewhich does not automatically load values when keys are requested.abstract <K1 extends K,V1 extends V>
AxelorCache<K1, V1> build(CacheLoader<? super K1, V1> loader) Builds anAxelorCachewhich either returns an already-loaded value for a given key or atomically computes or retrieves it using the suppliedCacheLoader.expireAfterAccess(Duration expireAfterAccess) Sets the duration after which cache entries will expire following the last access.expireAfterWrite(Duration expireAfterWrite) Sets the duration after which cache entries will expire following the last write.protected static <K,V> CacheBuilder <K, V> fromCacheName(String name) Constructs a newCacheBuilderinstance for the specified cache name.protected Stringstatic CacheProviderInfoReturns information about the current cache provider configuration.static CacheTypeprotected Durationprotected Durationprotected intprotected <K1 extends K,V1 extends V>
RemovalListener<K1, V1> protected booleanprotected booleanmaximumSize(int maximumSize) Sets the maximum number of entries the cache may contain.static <K,V> CacheBuilder <K, V> newBuilder(String name) Constructs a newCacheBuilderinstance.static <K,V> CacheBuilder <K, V> Constructs a newCacheBuilderinstance for an in-memory cache.<K1 extends K,V1 extends V>
CacheBuilder<K1, V1> removalListener(RemovalListener<? super K1, ? super V1> removalListener) Specifies a listener instance that caches should notify each time an entry is removed for anyreason.weakKeys()Specifies that the cache should use weak references for keys.Specifies that the cache should use weak references for values.
-
Constructor Details
-
CacheBuilder
-
CacheBuilder
-
-
Method Details
-
getCacheType
-
newBuilder
Constructs a newCacheBuilderinstance.The caller class is used together with the specified name as cache name.
The cache name is used to create a globally unique cache name, depending on the cache provider.
- Type Parameters:
K- the key type of the cacheV- the value type of the cache- Parameters:
name- the name used as suffix of the cache name- Returns:
- a new
CacheBuilderinstance
-
newInMemoryBuilder
Constructs a newCacheBuilderinstance for an in-memory cache.This currently uses Caffeine as the in-memory cache provider.
- Type Parameters:
K- the key type of the cacheV- the value type of the cache- Returns:
- a new
CacheBuilderinstance
-
fromCacheName
Constructs a newCacheBuilderinstance for the specified cache name.The cache name is used to create a globally unique cache name, depending on the cache provider.
- Type Parameters:
K- the key type of the cacheV- the value type of the cache- Parameters:
name- the name of the cache- Returns:
- a new
CacheBuilderinstance
-
getCacheProviderInfo
Returns information about the current cache provider configuration.- Returns:
- the cache provider information
-
getCacheName
-
getMaximumSize
protected int getMaximumSize() -
maximumSize
Sets the maximum number of entries the cache may contain.Depending on the cache provider, this may not be supported and approximation techniques may be used.
- Parameters:
maximumSize- the maximum size of the cache- Returns:
- this
CacheBuilderinstance (for chaining)
-
getExpireAfterWrite
-
expireAfterWrite
Sets the duration after which cache entries will expire following the last write.- Parameters:
expireAfterWrite- the duration after which entries will expire following the last write- Returns:
- this
CacheBuilderinstance (for chaining)
-
getExpireAfterAccess
-
expireAfterAccess
Sets the duration after which cache entries will expire following the last access.- Parameters:
expireAfterAccess- the duration after which entries will expire following the last access- Returns:
- this
CacheBuilderinstance (for chaining)
-
isWeakKeys
protected boolean isWeakKeys() -
weakKeys
Specifies that the cache should use weak references for keys.Depending on the cache provider, this may not be supported and approximation techniques may be used.
- Returns:
- this
CacheBuilderinstance (for chaining)
-
isWeakValues
protected boolean isWeakValues() -
weakValues
Specifies that the cache should use weak references for values.Depending on the cache provider, this may not be supported and approximation techniques may be used.
- Returns:
- this
CacheBuilderinstance (for chaining)
-
getRemovalListener
-
removalListener
public <K1 extends K,V1 extends V> CacheBuilder<K1,V1> removalListener(RemovalListener<? super K1, ? super V1> removalListener) Specifies a listener instance that caches should notify each time an entry is removed for anyreason.- Parameters:
removalListener- the listener instance- Returns:
- this
CacheBuilderinstance (for chaining)
-
build
Builds anAxelorCachewhich does not automatically load values when keys are requested.- Type Parameters:
K1- the key type of the cacheV1- the value type of the cache- Returns:
- a new
AxelorCacheinstance having the specified configuration
-
build
public abstract <K1 extends K,V1 extends V> AxelorCache<K1,V1> build(CacheLoader<? super K1, V1> loader) Builds anAxelorCachewhich either returns an already-loaded value for a given key or atomically computes or retrieves it using the suppliedCacheLoader.- Type Parameters:
K1- the key type of the cacheV1- the value type of the cache- Parameters:
loader- theCacheLoaderused to obtain new values- Returns:
- a new
AxelorCacheinstance having the specified configuration and using the specified loader
-