Package com.axelor.cache
Class CacheBuilder<K,V,B extends CacheBuilder<K,V,B>>
java.lang.Object
com.axelor.cache.CacheBuilder<K,V,B>
- 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 TypeMethodDescriptionfinal <K1 extends K,V1 extends V>
AxelorCache<K1, V1> build()Builds anAxelorCachewhich does not automatically load values when keys are requested.final <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.protected abstract <K1 extends K,V1 extends V>
AxelorCache<K1, V1> buildCache(String name) protected abstract <K1 extends K,V1 extends V>
AxelorCache<K1, V1> buildCache(String name, CacheLoader<? super K1, V1> loader) protected <K1 extends K,V1 extends V>
TenantAwareCache<K1, V1> createTenantAwareCache(Function<String, AxelorCache<K1, V1>> cacheFactory) 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, B extends CacheBuilder<K, V, B>>
BfromCacheName(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 booleanmaximumSize(int maximumSize) Sets the maximum number of entries the cache may contain.static <K,V, B extends CacheBuilder<K, V, B>>
BnewBuilder(String name) Constructs a newCacheBuilderinstance.static <K,V> CaffeineCacheBuilder <K, V> Constructs a newCaffeineCacheBuilderinstance for an in-memory cache.Disables data isolation per tenant.<K1 extends K,V1 extends V, B1 extends CacheBuilder<K1, V1, B1>>
CacheBuilder<K1, V1, B1> removalListener(RemovalListener<? super K1, ? super V1> removalListener) Specifies a listener instance that caches should notify each time an entry is removed for anyreason.protected Bself()
-
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 newCaffeineCacheBuilderinstance for an in-memory cache.- Type Parameters:
K- the key type of the cacheV- the value type of the cache- Returns:
- a new
CaffeineCacheBuilderinstance
-
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
-
self
-
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)
-
isTenantAware
protected boolean isTenantAware() -
nonTenantAware
Disables data isolation per tenant. The cache will be shared globally across all tenants when multi-tenancy is active.By default, when multi-tenancy is active, the cache automatically segregates entries based on the current tenant context.
- Returns:
- this
CacheBuilderinstance (for chaining)
-
getRemovalListener
-
removalListener
public <K1 extends K,V1 extends V, CacheBuilder<K1,B1 extends CacheBuilder<K1, V1, B1>> V1, removalListenerB1> (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
-
buildCache
-
build
public final <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
-
createTenantAwareCache
protected <K1 extends K,V1 extends V> TenantAwareCache<K1,V1> createTenantAwareCache(Function<String, AxelorCache<K1, V1>> cacheFactory) -
buildCache
protected abstract <K1 extends K,V1 extends V> AxelorCache<K1,V1> buildCache(String name, CacheLoader<? super K1, V1> loader)
-