Class CaffeineConfiguration<K,V>
java.lang.Object
com.github.benmanes.caffeine.jcache.configuration.CaffeineConfiguration<K,V>
- All Implemented Interfaces:
Serializable,CompleteConfiguration<K,,V> Configuration<K,V>
@NullMarked
public final class CaffeineConfiguration<K,V>
extends Object
implements CompleteConfiguration<K,V>
A JCache configuration with Caffeine specific settings.
The initial settings disable store by value so that entries are not copied when
crossing the Cache API boundary. If enabled and the Copier is not
explicitly set, then the JavaSerializationCopier will be used. This differs from
MutableConfiguration which enables store by value at construction.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCaffeineConfiguration(CompleteConfiguration<K, V> configuration) Returns a modifiable copy of the configuration. -
Method Summary
Modifier and TypeMethodDescriptionaddCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) booleanReturns a writer created by the configured factory or null if not set.@Nullable Factory<CacheWriter<? super K, ? super V>> Returns the expire after access in nanoseconds.Returns the expire after write in nanoseconds.Returns the maximum size to be used for the cache.Returns the maximum weight to be used for the cache.Returns the refresh after write in nanoseconds.booleanReturns if the cache writer factory is specified.inthashCode()Returns an unmodifiable copy of this configuration.booleanbooleanChecks whether native statistics collection is enabled in this cache.booleanbooleanbooleanbooleanremoveCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) setCacheLoaderFactory(@Nullable Factory<? extends CacheLoader<K, V>> factory) setCacheWriterFactory(@Nullable Factory<? extends CacheWriter<? super K, ? super V>> factory) setCopierFactory(Factory<Copier> factory) setExecutorFactory(Factory<Executor> factory) setExpireAfterAccess(OptionalLong expireAfterAccessNanos) Set the expire after write in nanoseconds.setExpireAfterWrite(OptionalLong expireAfterWriteNanos) Set the expire after write in nanoseconds.setExpiryPolicyFactory(@Nullable Factory<? extends ExpiryPolicy> factory) setManagementEnabled(boolean enabled) setMaximumSize(OptionalLong maximumSize) Set the maximum size.setMaximumWeight(OptionalLong maximumWeight) Set the maximum weight.setNativeStatisticsEnabled(boolean enabled) Sets whether native statistics gathering is enabled on a cache.setReadThrough(boolean isReadThrough) setRefreshAfterWrite(OptionalLong refreshAfterWriteNanos) Set the refresh after write in nanoseconds.setSchedulerFactory(Factory<Scheduler> factory) setStatisticsEnabled(boolean enabled) setStoreByValue(boolean isStoreByValue) setTickerFactory(Factory<Ticker> factory) setWriteThrough(boolean isWriteThrough)
-
Constructor Details
-
CaffeineConfiguration
public CaffeineConfiguration() -
CaffeineConfiguration
Returns a modifiable copy of the configuration.
-
-
Method Details
-
immutableCopy
Returns an unmodifiable copy of this configuration. -
getKeyType
- Specified by:
getKeyTypein interfaceConfiguration<K,V>
-
getValueType
- Specified by:
getValueTypein interfaceConfiguration<K,V>
-
setTypes
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> setTypes(Class<K> keyType, Class<V> valueType) -
getCacheEntryListenerConfigurations
- Specified by:
getCacheEntryListenerConfigurationsin interfaceCompleteConfiguration<K,V>
-
addCacheEntryListenerConfiguration
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> addCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) -
removeCacheEntryListenerConfiguration
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> removeCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) -
getCacheLoaderFactory
- Specified by:
getCacheLoaderFactoryin interfaceCompleteConfiguration<K,V>
-
setCacheLoaderFactory
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> setCacheLoaderFactory(@Nullable Factory<? extends CacheLoader<K, V>> factory) -
getCacheWriterFactory
- Specified by:
getCacheWriterFactoryin interfaceCompleteConfiguration<K,V>
-
getCacheWriter
Returns a writer created by the configured factory or null if not set. -
hasCacheWriter
public boolean hasCacheWriter()Returns if the cache writer factory is specified. -
setCacheWriterFactory
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> setCacheWriterFactory(@Nullable Factory<? extends CacheWriter<? super K, ? super V>> factory) -
getExpiryPolicyFactory
- Specified by:
getExpiryPolicyFactoryin interfaceCompleteConfiguration<K,V>
-
setExpiryPolicyFactory
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> setExpiryPolicyFactory(@Nullable Factory<? extends ExpiryPolicy> factory) -
isReadThrough
public boolean isReadThrough()- Specified by:
isReadThroughin interfaceCompleteConfiguration<K,V>
-
setReadThrough
-
isWriteThrough
public boolean isWriteThrough()- Specified by:
isWriteThroughin interfaceCompleteConfiguration<K,V>
-
setWriteThrough
-
isStoreByValue
public boolean isStoreByValue()- Specified by:
isStoreByValuein interfaceConfiguration<K,V>
-
setStoreByValue
-
isNativeStatisticsEnabled
public boolean isNativeStatisticsEnabled()Checks whether native statistics collection is enabled in this cache.The default value is
false.- Returns:
- true if native statistics collection is enabled
-
setNativeStatisticsEnabled
Sets whether native statistics gathering is enabled on a cache.- Parameters:
enabled- true to enable native statistics, false to disable.- Returns:
- the
CaffeineConfigurationto permit fluent-style method calls
-
isStatisticsEnabled
public boolean isStatisticsEnabled()- Specified by:
isStatisticsEnabledin interfaceCompleteConfiguration<K,V>
-
setStatisticsEnabled
-
isManagementEnabled
public boolean isManagementEnabled()- Specified by:
isManagementEnabledin interfaceCompleteConfiguration<K,V>
-
setManagementEnabled
-
getCopierFactory
-
setCopierFactory
- Parameters:
factory- theCopierFactory- Returns:
- the
CaffeineConfigurationto permit fluent-style method calls
-
getSchedulerFactory
-
setSchedulerFactory
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> setSchedulerFactory(Factory<Scheduler> factory) - Parameters:
factory- theSchedulerFactory- Returns:
- the
CaffeineConfigurationto permit fluent-style method calls
-
getTickerFactory
-
setTickerFactory
- Parameters:
factory- theTickerFactory- Returns:
- the
CaffeineConfigurationto permit fluent-style method calls
-
getExecutorFactory
-
setExecutorFactory
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> setExecutorFactory(Factory<Executor> factory) - Parameters:
factory- theExecutorFactory- Returns:
- the
CaffeineConfigurationto permit fluent-style method calls
-
getRefreshAfterWrite
Returns the refresh after write in nanoseconds.- Returns:
- the duration in nanoseconds
-
setRefreshAfterWrite
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> setRefreshAfterWrite(OptionalLong refreshAfterWriteNanos) Set the refresh after write in nanoseconds.- Parameters:
refreshAfterWriteNanos- the duration in nanoseconds- Returns:
- the
CaffeineConfigurationto permit fluent-style method calls
-
getExpireAfterWrite
Returns the expire after write in nanoseconds.- Returns:
- the duration in nanoseconds
-
setExpireAfterWrite
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> setExpireAfterWrite(OptionalLong expireAfterWriteNanos) Set the expire after write in nanoseconds.- Parameters:
expireAfterWriteNanos- the duration in nanoseconds- Returns:
- the
CaffeineConfigurationto permit fluent-style method calls
-
getExpireAfterAccess
Returns the expire after access in nanoseconds.- Returns:
- the duration in nanoseconds
-
setExpireAfterAccess
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> setExpireAfterAccess(OptionalLong expireAfterAccessNanos) Set the expire after write in nanoseconds.- Parameters:
expireAfterAccessNanos- the duration in nanoseconds- Returns:
- the
CaffeineConfigurationto permit fluent-style method calls
-
getExpiryFactory
-
setExpiryFactory
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> setExpiryFactory(Optional<Factory<? extends Expiry<K, V>>> factory) - Parameters:
factory- theExpiryFactory- Returns:
- the
CaffeineConfigurationto permit fluent-style method calls
-
getMaximumSize
Returns the maximum size to be used for the cache.- Returns:
- the maximum size
-
setMaximumSize
Set the maximum size.- Parameters:
maximumSize- the maximum size- Returns:
- the
CaffeineConfigurationto permit fluent-style method calls
-
getMaximumWeight
Returns the maximum weight to be used for the cache.- Returns:
- the maximum weight
-
setMaximumWeight
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> setMaximumWeight(OptionalLong maximumWeight) Set the maximum weight.- Parameters:
maximumWeight- the maximum weighted size- Returns:
- the
CaffeineConfigurationto permit fluent-style method calls
-
getWeigherFactory
-
setWeigherFactory
@CanIgnoreReturnValue public CaffeineConfiguration<K,V> setWeigherFactory(Optional<Factory<? extends Weigher<K, V>>> factory) - Parameters:
factory- theWeigherFactory- Returns:
- the
CaffeineConfigurationto permit fluent-style method calls
-
equals
-
hashCode
-