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
ConstructorsModifierConstructorDescriptionprotected
CacheBuilder
(CacheBuilder<K, V> builder) protected
CacheBuilder
(String cacheName) -
Method Summary
Modifier and TypeMethodDescriptionabstract <K1 extends K,
V1 extends V>
AxelorCache<K1, V1> build()
Builds anAxelorCache
which 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 anAxelorCache
which 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 newCacheBuilder
instance for the specified cache name.protected String
static CacheProviderInfo
Returns information about the current cache provider configuration.static CacheType
protected Duration
protected Duration
protected int
protected <K1 extends K,
V1 extends V>
RemovalListener<K1, V1> protected boolean
protected boolean
maximumSize
(int maximumSize) Sets the maximum number of entries the cache may contain.static <K,
V> CacheBuilder <K, V> newBuilder
(String name) Constructs a newCacheBuilder
instance.static <K,
V> CacheBuilder <K, V> Constructs a newCacheBuilder
instance 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 newCacheBuilder
instance.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
CacheBuilder
instance
-
newInMemoryBuilder
Constructs a newCacheBuilder
instance 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
CacheBuilder
instance
-
fromCacheName
Constructs a newCacheBuilder
instance 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
CacheBuilder
instance
-
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
CacheBuilder
instance (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
CacheBuilder
instance (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
CacheBuilder
instance (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
CacheBuilder
instance (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
CacheBuilder
instance (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
CacheBuilder
instance (for chaining)
-
build
Builds anAxelorCache
which 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
AxelorCache
instance having the specified configuration
-
build
public abstract <K1 extends K,V1 extends V> AxelorCache<K1,V1> build(CacheLoader<? super K1, V1> loader) Builds anAxelorCache
which 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
- theCacheLoader
used to obtain new values- Returns:
- a new
AxelorCache
instance having the specified configuration and using the specified loader
-