A value object used to represent cache configuration.
Construction Patterns
The recommended way of creating a
Cache
in Ehcache 2.0 and above is to create a
CacheConfiguration
object
and pass it to the
Cache
constructor. See
Cache.Cache(CacheConfiguration)
.
This class supports setter injection and also the fluent builder pattern.
Cache cache = new Cache(new CacheConfiguration("test2", 1000).eternal(true).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO));
Rather than proliferation of new constructors as new versions of Ehcache come out, it intended to add the new configuration to this
class.
Another way to set configuration is declaratively in the
ehcache.xml
configuration file.
<cache name="testCache1"
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="10"
overflowToDisk="true"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="120"
maxEntriesLocalDisk="10000"
Dynamic Configuration
CacheConfiguration instances retrieved from Cache instances allow the dynamic
modification of certain configuration properties. Currently the dynamic
properties are:
Time To Idle
Time To Live
Max Entries in Local Heap
Max Entries on Local Disk
Dynamic changes are however not persistent across cache restarts. On restart
the cache configuration will be reloaded from its original source, erasing any
changes made previously at runtime.
protected CacheConfiguration.BootstrapCacheLoaderFactoryConfiguration
bootstrapCacheLoaderFactoryConfiguration
The BootstrapCacheLoaderFactoryConfiguration.
protected List<CacheConfiguration.CacheDecoratorFactoryConfiguration>
cacheDecoratorConfigurations
The cache decorator factories added by BeanUtils.
protected List<CacheConfiguration.CacheEventListenerFactoryConfiguration>
cacheEventListenerConfigurations
The event listener factories added by BeanUtils.
protected CacheConfiguration.CacheExceptionHandlerFactoryConfiguration
cacheExceptionHandlerFactoryConfiguration
The CacheExceptionHandlerFactoryConfiguration.
protected List<CacheConfiguration.CacheExtensionFactoryConfiguration>
cacheExtensionConfigurations
The cache extension factories added by BeanUtils.
protected List<CacheConfiguration.CacheLoaderFactoryConfiguration>
cacheLoaderConfigurations
The cache loader factories added by BeanUtils.
protected long
cacheLoaderTimeoutMillis
Timeout in milliseconds for CacheLoader related calls
protected CacheWriterConfiguration
cacheWriterConfiguration
The CacheWriterConfiguration.
protected boolean
clearOnFlush
Sets whether the MemoryStore should be cleared when
flush()
is called on the cache - true by default.
static CacheWriterConfiguration
DEFAULT_CACHE_WRITER_CONFIGURATION
The default cacheWriterConfiguration
static boolean
DEFAULT_CLEAR_ON_FLUSH
Default value for clearOnFlush
static boolean
DEFAULT_COPY_ON_READ
Default value for copyOnRead
static boolean
DEFAULT_COPY_ON_WRITE
Default value for copyOnRead
static CopyStrategyConfiguration
DEFAULT_COPY_STRATEGY_CONFIGURATION
Default copyStrategyConfiguration
static int
DEFAULT_DISK_ACCESS_STRIPES
Default number of diskAccessStripes.
static boolean
DEFAULT_DISK_PERSISTENT
Deprecated. The diskPersistent
attribute has been replaced with persistence(PersistenceConfiguration)
.
static boolean
DEFAULT_ETERNAL_VALUE
Default eternal value
static long
DEFAULT_EXPIRY_THREAD_INTERVAL_SECONDS
The default interval between runs of the expiry thread.
static boolean
DEFAULT_LOGGING
Logging is off by default.
static long
DEFAULT_MAX_BYTES_OFF_HEAP
Default maxBytesOffHeap value
static long
DEFAULT_MAX_BYTES_ON_DISK
Default maxBytesOnDisk value
static long
DEFAULT_MAX_BYTES_ON_HEAP
Default maxBytesOnHeap value
static int
DEFAULT_MAX_ELEMENTS_ON_DISK
Default value for maxElementsOnDisk
static MemoryStoreEvictionPolicy
DEFAULT_MEMORY_STORE_EVICTION_POLICY
The default memory store eviction policy is LRU.
static int
DEFAULT_SPOOL_BUFFER_SIZE
Set a buffer size for the spool of approx 30MB.
static boolean
DEFAULT_STATISTICS
Default value for statistics
static CacheConfiguration.TransactionalMode
DEFAULT_TRANSACTIONAL_MODE
Default value for transactionalMode
static long
DEFAULT_TTI
Default value for tti
static long
DEFAULT_TTL
Default value for ttl
protected int
diskAccessStripes
The number of concurrent disk access stripes.
protected long
diskExpiryThreadIntervalSeconds
The interval in seconds between runs of the disk expiry thread.
protected Boolean
diskPersistent
Deprecated. The diskPersistent
attribute has been replaced with persistence(PersistenceConfiguration)
.
protected int
diskSpoolBufferSizeMB
The size of the disk spool used to buffer writes
protected boolean
eternal
Sets whether elements are eternal.
protected Set<CacheConfigurationListener>
listeners
The listeners for this configuration.
protected boolean
logging
Indicates whether logging is enabled or not.
protected int
maxElementsOnDisk
the maximum objects to be held in the DiskStore
.
protected Integer
maxEntriesLocalHeap
the maximum objects to be held in the MemoryStore
.
protected MemoryStoreEvictionPolicy
memoryStoreEvictionPolicy
The policy used to evict elements from the MemoryStore
.
protected String
the name of the cache.
protected Boolean
overflowToDisk
Deprecated. The overflowToDisk
attribute has been replaced with PersistenceConfiguration.Strategy.LOCALTEMPSWAP
.
protected Boolean
overflowToOffHeap
whether elements can overflow to off heap memory when the in-memory cache
has reached the set limit.
protected PinningConfiguration
pinningConfiguration
The PinningConfiguration.
protected TerracottaConfiguration
terracottaConfiguration
The TerracottaConfiguration.
protected long
timeToIdleSeconds
the time to idle for an element before it expires.
protected long
timeToLiveSeconds
Sets the time to idle for an element before it expires.
addBootstrapCacheLoaderFactory(CacheConfiguration.BootstrapCacheLoaderFactoryConfiguration factory)
Allows BeanHandler to add the CacheManagerEventListener to the configuration.
addCacheDecoratorFactory(CacheConfiguration.CacheDecoratorFactoryConfiguration factory)
Used by BeanUtils to add each cacheDecoratorFactory to the cache configuration.
addCacheEventListenerFactory(CacheConfiguration.CacheEventListenerFactoryConfiguration factory)
Used by BeanUtils to add cacheEventListenerFactory elements to the cache configuration.
addCacheExceptionHandlerFactory(CacheConfiguration.CacheExceptionHandlerFactoryConfiguration factory)
Add the CacheExceptionHandlerFactory to the configuration.
addCacheExtensionFactory(CacheConfiguration.CacheExtensionFactoryConfiguration factory)
Used by BeanUtils to add cacheExtensionFactory elements to the cache configuration.
addCacheLoaderFactory(CacheConfiguration.CacheLoaderFactoryConfiguration factory)
Used by BeanUtils to add each cacheLoaderFactory to the cache configuration.
addCacheWriter(CacheWriterConfiguration cacheWriterConfiguration)
Allows BeanHandler to add the CacheWriterConfiguration to the configuration.
boolean
addConfigurationListener(CacheConfigurationListener listener)
Add a listener to this cache configuration
addCopyStrategy(CopyStrategyConfiguration copyStrategyConfiguration)
Sets the CopyStrategyConfiguration for this cache
boolean
addDynamicSearchListener(DynamicSearchListener listener)
Add a dynamic extractor configuration listener
addElementValueComparator(ElementValueComparatorConfiguration elementValueComparatorConfiguration)
Sets the ElementValueComparatorConfiguration for this cache
addPersistence(PersistenceConfiguration persistenceConfiguration)
Sets the PersistenceConfiguration for this cache.
addPinning(PinningConfiguration pinningConfiguration)
Allows BeanHandler to add the PinningConfiguration to the configuration.
addSearchable(Searchable searchable)
Add configuration to make this cache searchable
addSizeOfPolicy(SizeOfPolicyConfiguration sizeOfPolicyConfiguration)
Sets the SizeOfPolicyConfiguration for this cache.
addTerracotta(TerracottaConfiguration terracottaConfiguration)
Allows BeanHandler to add the TerracottaConfiguration to the configuration.
CacheConfiguration
bootstrapCacheLoaderFactory(CacheConfiguration.BootstrapCacheLoaderFactoryConfiguration factory)
CacheConfiguration.BootstrapCacheLoaderFactoryConfiguration
getBootstrapCacheLoaderFactoryConfiguration()
Accessor
List<CacheConfiguration.CacheDecoratorFactoryConfiguration>
getCacheDecoratorConfigurations()
Accessor
getCacheEventListenerConfigurations()
Accessor
CacheConfiguration.CacheExceptionHandlerFactoryConfiguration
getCacheExceptionHandlerFactoryConfiguration()
Accessor
getCacheExtensionConfigurations()
Accessor
getCacheLoaderConfigurations()
Accessor
getCacheLoaderTimeoutMillis()
Accessor
CacheWriterConfiguration
getCacheWriterConfiguration()
Accessor
ReadWriteCopyStrategy<Element>
getCopyStrategy()
Getter to the CopyStrategy set in the config (really? how?).
CopyStrategyConfiguration
getCopyStrategyConfiguration()
Returns the copyStrategyConfiguration
getDiskAccessStripes()
Accessor
getDiskExpiryThreadIntervalSeconds()
Accessor
getDiskSpoolBufferSizeMB()
Accessor
DynamicAttributesExtractor
getDynamicExtractor()
Accessor
ElementValueComparatorConfiguration
getElementValueComparatorConfiguration()
Returns the elementComparatorConfiguration
boolean
getLogging()
Only used when cache is clustered with Terracotta
getMaxBytesLocalDisk()
The maximum amount of bytes the cache should occupy on disk
String
getMaxBytesLocalDiskAsString()
The string form of the maximum amount of bytes the cache should occupy on disk
Integer
getMaxBytesLocalDiskPercentage()
Getter for maximum bytes on disk expressed as a percentage
getMaxBytesLocalHeap()
The maximum amount of bytes the cache should occupy on heap
String
getMaxBytesLocalHeapAsString()
The string form of the maximum amount of bytes the cache should occupy on heap
Integer
getMaxBytesLocalHeapPercentage()
Getter for maximum bytes on heap expressed as a percentage
getMaxBytesLocalOffHeap()
The maximum amount of bytes the cache should occupy off heap
String
getMaxBytesLocalOffHeapAsString()
The string form of the maximum amount of bytes the cache should occupy off heap
Integer
getMaxBytesLocalOffHeapPercentage()
Getter for maximum bytes off heap expressed as a percentage
getMaxElementsInMemory()
Deprecated. use getMaxEntriesLocalHeap()
getMaxElementsOnDisk()
Accessor
getMaxEntriesLocalDisk()
Configured maximum number of entries for the local disk store.
getMaxEntriesLocalHeap()
Configured maximum number of entries for the local memory heap.
String
getMaxMemoryOffHeap()
Deprecated. See getMaxBytesLocalOffHeapAsString()
getMaxMemoryOffHeapInBytes()
Deprecated. getMaxBytesLocalOffHeap()
MemoryStoreEvictionPolicy
getMemoryStoreEvictionPolicy()
Accessor
String
getName()
Accessor
PersistenceConfiguration
getPersistenceConfiguration()
Accessor
PinningConfiguration
getPinningConfiguration()
Accessor
Searchable
getSearchable()
Get the search configuration for this cache (if any)
Map<String,SearchAttribute>
getSearchAttributes()
Get the defined search attributes indexed by attribute name
SizeOfPolicyConfiguration
getSizeOfPolicyConfiguration()
Accessor
boolean
getStatistics()
Gets whether the cache's statistics will be enabled at startup
TerracottaConfiguration
getTerracottaConfiguration()
Accessor
TerracottaConfiguration.Consistency
getTerracottaConsistency()
Accessor
getTimeToIdleSeconds()
Accessor
getTimeToLiveSeconds()
Accessor
CacheConfiguration.TransactionalMode
getTransactionalMode()
To what transactionalMode was the Cache set
internalSetDiskCapacity(int capacity)
Intended for internal use only, and subject to change.
internalSetLogging(boolean logging)
Intended for internal use only, and subject to change.
internalSetMemCapacity(int capacity)
Intended for internal use only, and subject to change.
internalSetMemCapacityInBytes(long capacity)
Intended for internal use only, and subject to change.
internalSetTimeToIdle(long timeToIdle)
Intended for internal use only, and subject to change.
internalSetTimeToLive(long timeToLive)
Intended for internal use only, and subject to change.
boolean
isClearOnFlush()
Accessor
boolean
isCopyOnRead()
Whether the Cache should copy elements it returns
boolean
isCopyOnWrite()
Whether the Cache should copy elements it gets
boolean
isCountBasedTuned()
Whether this cache is Count based
boolean
isDiskPersistent()
Deprecated. The diskPersistent
attribute has been replaced with persistence(PersistenceConfiguration)
.
boolean
isEternal()
Accessor
boolean
isFrozen()
CacheConfiguration
memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy memoryStoreEvictionPolicy)
Builder which Sets the eviction policy.
CacheConfiguration
memoryStoreEvictionPolicy(String memoryStoreEvictionPolicy)
Builder that sets the eviction policy.
CacheConfiguration
name(String name)
Builder to set the name of the cache.
CacheConfiguration
overflowToDisk(boolean overflowToDisk)
Deprecated. The overflowToDisk
attribute has been replaced with PersistenceConfiguration.Strategy.LOCALTEMPSWAP
.
CacheConfiguration
overflowToOffHeap(boolean overflowToOffHeap)
Builder to enable or disable offheap store for the cache.
CacheConfiguration
persistence(PersistenceConfiguration persistenceConfiguration)
Builder to set the PersistenceConfiguration for this cache.
CacheConfiguration
pinning(PinningConfiguration pinningConfiguration)
setMemoryStoreEvictionPolicyFromObject(MemoryStoreEvictionPolicy memoryStoreEvictionPolicy)
Sets the eviction policy.
setName(String name)
Sets the name of the cache.
setOverflowToDisk(boolean overflowToDisk)
Deprecated. The overflowToDisk
attribute has been replaced with PersistenceConfiguration.Strategy.LOCALTEMPSWAP
.
setOverflowToOffHeap(boolean overflowToOffHeap)
Enables or disables offheap store for the cache.
setStatistics(boolean enabled)
Sets whether the cache's statistics are enabled.
setTimeToIdleSeconds(long timeToIdleSeconds)
Sets the time to idle for an element before it expires.
setTimeToLiveSeconds(long timeToLiveSeconds)
Sets the time to idle for an element before it expires.
setTransactionalMode(String transactionalMode)
Sets the transactionalMode
setupFor(CacheManager cacheManager)
Sets up the CacheConfiguration for runtime consumption, also registers this cache configuration with the cache manager's configuration
setupFor(CacheManager cacheManager,
boolean register)
Sets up the CacheConfiguration for runtime consumption
CacheConfiguration
sizeOfPolicy(SizeOfPolicyConfiguration sizeOfPolicyConfiguration)
Builder to set the SizeOfPolicyConfiguration for this cache.
CacheConfiguration
statistics(boolean statistics)
Builder which sets whether the cache's statistics are enabled.
CacheConfiguration
terracotta(TerracottaConfiguration terracottaConfiguration)
CacheConfiguration
transactionalMode(CacheConfiguration.TransactionalMode transactionalMode)
Builder which sets the transactionalMode
CacheConfiguration
transactionalMode(String transactionalMode)
Builder which sets the transactionalMode
Collection<ConfigError>
validate(Configuration configuration)
Validates the configuration
validateCompleteConfiguration()
Used to validate what should be a complete Cache Configuration.
validateConfiguration()
Used to validate a Cache Configuration.
DEFAULT_EXPIRY_THREAD_INTERVAL_SECONDS
public static final long DEFAULT_EXPIRY_THREAD_INTERVAL_SECONDS
The default interval between runs of the expiry thread.
See Also:
Constant Field Values
public static final int
DEFAULT_SPOOL_BUFFER_SIZE
Set a buffer size for the spool of approx 30MB.
See Also:
Constant Field Values
DEFAULT_MEMORY_STORE_EVICTION_POLICY
public static final
MemoryStoreEvictionPolicy
DEFAULT_MEMORY_STORE_EVICTION_POLICY
The default memory store eviction policy is LRU.
DEFAULT_CACHE_WRITER_CONFIGURATION
public static final
CacheWriterConfiguration
DEFAULT_CACHE_WRITER_CONFIGURATION
The default cacheWriterConfiguration
DEFAULT_TRANSACTIONAL_MODE
public static final
CacheConfiguration.TransactionalMode
DEFAULT_TRANSACTIONAL_MODE
Default value for transactionalMode
public static final boolean
DEFAULT_DISK_PERSISTENT
Deprecated.
The
diskPersistent
attribute has been replaced with
persistence(PersistenceConfiguration)
.
Default value for diskPersistent
See Also:
Constant Field Values
DEFAULT_COPY_STRATEGY_CONFIGURATION
public static final
CopyStrategyConfiguration
DEFAULT_COPY_STRATEGY_CONFIGURATION
Default copyStrategyConfiguration
protected volatile
Integer
maxEntriesLocalHeap
the maximum objects to be held in the
MemoryStore
.
0
translates to no-limit.
protected volatile int
maxElementsOnDisk
the maximum objects to be held in the
DiskStore
.
0
translates to no-limit.
memoryStoreEvictionPolicy
protected volatile
MemoryStoreEvictionPolicy
memoryStoreEvictionPolicy
The policy used to evict elements from the
MemoryStore
.
This can be one of:
LRU - least recently used
LFU - Less frequently used
FIFO - first in first out, the oldest element by creation time
The default value is LRU
Since:
protected volatile boolean
clearOnFlush
Sets whether the MemoryStore should be cleared when
flush()
is called on the cache - true by default.
protected volatile boolean
eternal
Sets whether elements are eternal. If eternal, timeouts are ignored and the element
is never expired.
protected volatile long
timeToIdleSeconds
the time to idle for an element before it expires. Is only used
if the element is not eternal.A value of 0 means do not check for idling.
protected volatile long
timeToLiveSeconds
Sets the time to idle for an element before it expires. Is only used
if the element is not eternal. This attribute is optional in the configuration.
A value of 0 means do not check time to live.
protected volatile
Boolean
overflowToDisk
Deprecated.
The
overflowToDisk
attribute has been replaced with
PersistenceConfiguration.Strategy.LOCALTEMPSWAP
.
whether elements can overflow to disk when the in-memory cache
has reached the set limit.
protected volatile long
diskExpiryThreadIntervalSeconds
The interval in seconds between runs of the disk expiry thread.
2 minutes is the default.
This is not the same thing as time to live or time to idle. When the thread runs it checks
these things. So this value is how often we check for expiry.
protected volatile boolean
logging
Indicates whether logging is enabled or not. False by default.
Only used when cache is clustered with Terracotta.
protected volatile
Boolean
overflowToOffHeap
whether elements can overflow to off heap memory when the in-memory cache
has reached the set limit.
cacheEventListenerConfigurations
protected volatile
List
<
CacheConfiguration.CacheEventListenerFactoryConfiguration
>
cacheEventListenerConfigurations
The event listener factories added by BeanUtils.
cacheExtensionConfigurations
protected volatile
List
<
CacheConfiguration.CacheExtensionFactoryConfiguration
>
cacheExtensionConfigurations
The cache extension factories added by BeanUtils.
bootstrapCacheLoaderFactoryConfiguration
protected
CacheConfiguration.BootstrapCacheLoaderFactoryConfiguration
bootstrapCacheLoaderFactoryConfiguration
The BootstrapCacheLoaderFactoryConfiguration.
cacheExceptionHandlerFactoryConfiguration
protected
CacheConfiguration.CacheExceptionHandlerFactoryConfiguration
cacheExceptionHandlerFactoryConfiguration
The CacheExceptionHandlerFactoryConfiguration.
cacheLoaderConfigurations
protected volatile
List
<
CacheConfiguration.CacheLoaderFactoryConfiguration
>
cacheLoaderConfigurations
The cache loader factories added by BeanUtils.
cacheDecoratorConfigurations
protected volatile
List
<
CacheConfiguration.CacheDecoratorFactoryConfiguration
>
cacheDecoratorConfigurations
The cache decorator factories added by BeanUtils.
Default constructor.
Note that an empty Cache is not valid and must have extra configuration added which can be done
through the fluent methods in this class. Call
validateConfiguration()
to check your configuration.
See Also:
validateCompleteConfiguration()
Create a new cache configuration.
Extra configuration can added after construction via the fluent methods in this class.
Call
validateConfiguration()
to check your configuration.
Parameters:
name
- the name of the cache. Note that "default" is a reserved name for the defaultCache.
maxEntriesLocalHeap
- the maximum number of elements in memory, before they are evicted (0 == no limit)
See Also:
validateCompleteConfiguration()
Parameters:
name
- the cache name. This must be unique. The / character is illegal. The # character does not work with RMI replication.
Returns:
this configuration instance
See Also:
setName(String)
Enables or disables logging for the cache
This property can be modified dynamically while the cache is operating.
Only used when cache is clustered with Terracotta
overflowToOffHeap
public
CacheConfiguration
overflowToOffHeap
(boolean overflowToOffHeap)
Builder to enable or disable offheap store for the cache.
addSizeOfPolicy
public void
addSizeOfPolicy
(
SizeOfPolicyConfiguration
sizeOfPolicyConfiguration)
Sets the SizeOfPolicyConfiguration for this cache.
sizeOfPolicy
public
CacheConfiguration
sizeOfPolicy
(
SizeOfPolicyConfiguration
sizeOfPolicyConfiguration)
Builder to set the SizeOfPolicyConfiguration for this cache.
addPersistence
public void
addPersistence
(
PersistenceConfiguration
persistenceConfiguration)
Sets the PersistenceConfiguration for this cache.
persistence
public
CacheConfiguration
persistence
(
PersistenceConfiguration
persistenceConfiguration)
Builder to set the PersistenceConfiguration for this cache.
public final void
setMaxMemoryOffHeap
(
String
maxMemoryOffHeap)
Deprecated.
See
setMaxBytesLocalOffHeap(java.lang.String)
Sets the max off heap memory size allocated for this cache.
public
CacheConfiguration
maxMemoryOffHeap
(
String
maxMemoryOffHeap)
Deprecated.
See
maxBytesLocalOffHeap(long, net.sf.ehcache.config.MemoryUnit)
Builder to set the max off heap memory size allocated for this cache.
public final
CacheConfiguration
logging
(boolean enable)
Builder to enable or disable logging for the cache
This property can be modified dynamically while the cache is operating.
Only used when cache is clustered with Terracotta
public final void
setMaxElementsInMemory
(int maxElementsInMemory)
Deprecated.
use
setMaxEntriesLocalHeap(long)
Sets the maximum objects to be held in memory (0 = no limit).
This property can be modified dynamically while the cache is operating.
public final void
setMaxEntriesLocalHeap
(long maxEntriesInMemory)
Sets the maximum objects to be held in local heap memory (0 = no limit).
This property can be modified dynamically while the cache is operating.
@Deprecated
public final
CacheConfiguration
maxElementsInMemory
(int maxElementsInMemory)
Deprecated.
use
maxEntriesLocalHeap(int)
Builder that sets the maximum objects to be held in memory (0 = no limit).
This property can be modified dynamically while the cache is operating.
Parameters:
maxElementsInMemory
- The maximum number of elements in memory, before they are evicted (0 == no limit)
Returns:
this configuration instance
maxEntriesLocalHeap
public final
CacheConfiguration
maxEntriesLocalHeap
(int maxElementsInMemory)
Builder that sets the maximum objects to be held in memory (0 = no limit).
This property can be modified dynamically while the cache is operating.
Parameters:
maxElementsInMemory
- The maximum number of elements in memory, before they are evicted (0 == no limit)
Returns:
this configuration instance
setCacheLoaderTimeoutMillis
public final void
setCacheLoaderTimeoutMillis
(long cacheLoaderTimeoutMillis)
Sets the timeout for CacheLoader execution (0 = no timeout).
setMemoryStoreEvictionPolicy
public final void
setMemoryStoreEvictionPolicy
(
String
memoryStoreEvictionPolicy)
Sets the eviction policy. An invalid argument will set it to LRU.
memoryStoreEvictionPolicy
public final
CacheConfiguration
memoryStoreEvictionPolicy
(
String
memoryStoreEvictionPolicy)
Builder that sets the eviction policy. An invalid argument will set it to null.
Parameters:
memoryStoreEvictionPolicy
- a String representation of the policy. One of "LRU", "LFU" or "FIFO".
Returns:
this configuration instance
See Also:
setMemoryStoreEvictionPolicy(String)
setMemoryStoreEvictionPolicyFromObject
public final void
setMemoryStoreEvictionPolicyFromObject
(
MemoryStoreEvictionPolicy
memoryStoreEvictionPolicy)
Sets the eviction policy. This method has a strange name to workaround a problem with XML parsing.
memoryStoreEvictionPolicy
public final
CacheConfiguration
memoryStoreEvictionPolicy
(
MemoryStoreEvictionPolicy
memoryStoreEvictionPolicy)
Builder which Sets the eviction policy. An invalid argument will set it to null.
public final void
setClearOnFlush
(boolean clearOnFlush)
Sets whether the MemoryStore should be cleared when
flush()
is called on the cache - true by default.
public final
CacheConfiguration
clearOnFlush
(boolean clearOnFlush)
Builder which sets whether the MemoryStore should be cleared when
flush()
is called on the cache - true by default.
public final void
setTimeToIdleSeconds
(long timeToIdleSeconds)
Sets the time to idle for an element before it expires. Is only used if the element is not eternal. This can be overidden in
Element
This property can be modified dynamically while the cache is operating.
timeToIdleSeconds
public final
CacheConfiguration
timeToIdleSeconds
(long timeToIdleSeconds)
Builder which sets the time to idle for an element before it expires. Is only used if the element is not eternal.
This default can be overridden in
Element
This property can be modified dynamically while the cache is operating.
Parameters:
timeToIdleSeconds
- the default amount of time to live for an element from its last accessed or modified date
Returns:
this configuration instance
See Also:
setTimeToIdleSeconds(long)
public final void
setTimeToLiveSeconds
(long timeToLiveSeconds)
Sets the time to idle for an element before it expires. Is only used if the element is not eternal.
This default can be overridden in
Element
This property can be modified dynamically while the cache is operating.
timeToLiveSeconds
public final
CacheConfiguration
timeToLiveSeconds
(long timeToLiveSeconds)
Builder which sets the time to idle for an element before it expires. Is only used if the element is not eternal.
This default can be overridden in
Element
This property can be modified dynamically while the cache is operating.
Parameters:
timeToLiveSeconds
- the default amount of time to live for an element from its creation date
Returns:
this configuration instance
See Also:
setTimeToLiveSeconds(long)
public final void
setOverflowToDisk
(boolean overflowToDisk)
Deprecated.
The
overflowToDisk
attribute has been replaced with
PersistenceConfiguration.Strategy.LOCALTEMPSWAP
.
Sets whether elements can overflow to disk when the in-memory cache has reached the set limit.
public final
CacheConfiguration
overflowToDisk
(boolean overflowToDisk)
Deprecated.
The
overflowToDisk
attribute has been replaced with
PersistenceConfiguration.Strategy.LOCALTEMPSWAP
.
Builder which sets whether elements can overflow to disk when the in-memory cache has reached the set limit.
public final void
setDiskPersistent
(boolean diskPersistent)
Deprecated.
The
diskPersistent
attribute has been replaced with
persistence(PersistenceConfiguration)
.
Sets whether the disk store persists between CacheManager instances. Note that this operates independently of
overflowToDisk
.
public final
CacheConfiguration
diskPersistent
(boolean diskPersistent)
Deprecated.
The
diskPersistent
attribute has been replaced with
persistence(PersistenceConfiguration)
.
Builder which sets whether the disk store persists between CacheManager instances. Note that this operates independently of
overflowToDisk
.
public void
setDiskSpoolBufferSizeMB
(int diskSpoolBufferSizeMB)
Sets the disk spool size, which is used to buffer writes to the DiskStore.
If not set it defaults to
DEFAULT_SPOOL_BUFFER_SIZE
diskSpoolBufferSizeMB
public final
CacheConfiguration
diskSpoolBufferSizeMB
(int diskSpoolBufferSizeMB)
Builder which sets the disk spool size, which is used to buffer writes to the DiskStore.
If not set it defaults to
DEFAULT_SPOOL_BUFFER_SIZE
public void
setDiskAccessStripes
(int stripes)
Sets the number of disk stripes. RandomAccessFiles used to access the data file. By default there
is one stripe.
public final
CacheConfiguration
diskAccessStripes
(int stripes)
Builder which sets the number of disk stripes. RandomAccessFiles used to access the data file. By default there
is one stripe.
public void
setMaxElementsOnDisk
(int maxElementsOnDisk)
Sets the maximum number elements on Disk. 0 means unlimited.
This property can be modified dynamically while the cache is operating.
public void
setMaxEntriesLocalDisk
(long maxEntriesOnDisk)
Sets the maximum number elements on Disk. 0 means unlimited.
This property can be modified dynamically while the cache is operating.
maxElementsOnDisk
public final
CacheConfiguration
maxElementsOnDisk
(int maxElementsOnDisk)
Builder which sets the maximum number elements on Disk. 0 means unlimited.
This property can be modified dynamically while the cache is operating.
Parameters:
maxElementsOnDisk
- the maximum number of Elements to allow on the disk. 0 means unlimited.
Returns:
this configuration instance
See Also:
setMaxElementsOnDisk(int)
maxEntriesLocalDisk
public final
CacheConfiguration
maxEntriesLocalDisk
(int maxElementsOnDisk)
Builder which sets the maximum number elements on Disk. 0 means unlimited.
This property can be modified dynamically while the cache is operating.
Parameters:
maxElementsOnDisk
- the maximum number of Elements to allow on the disk. 0 means unlimited.
Returns:
this configuration instance
See Also:
setMaxElementsOnDisk(int)
setDiskExpiryThreadIntervalSeconds
public final void
setDiskExpiryThreadIntervalSeconds
(long diskExpiryThreadIntervalSeconds)
Sets the interval in seconds between runs of the disk expiry thread.
2 minutes is the default.
This is not the same thing as time to live or time to idle. When the thread runs it checks
these things. So this value is how often we check for expiry.
diskExpiryThreadIntervalSeconds
public final
CacheConfiguration
diskExpiryThreadIntervalSeconds
(long diskExpiryThreadIntervalSeconds)
Builder which sets the interval in seconds between runs of the disk expiry thread.
2 minutes is the default.
This is not the same thing as time to live or time to idle. When the thread runs it checks
these things. So this value is how often we check for expiry.
public
ReadWriteCopyStrategy
<
Element
>
getCopyStrategy
()
Getter to the CopyStrategy set in the config (really? how?).
This will always return the same unique instance per cache
addCopyStrategy
public void
addCopyStrategy
(
CopyStrategyConfiguration
copyStrategyConfiguration)
Sets the CopyStrategyConfiguration for this cache
addElementValueComparator
public void
addElementValueComparator
(
ElementValueComparatorConfiguration
elementValueComparatorConfiguration)
Sets the ElementValueComparatorConfiguration for this cache
setDynamicAttributesExtractor
public void
setDynamicAttributesExtractor
(
DynamicAttributesExtractor
extractor)
Sets dynamic search attributes extractor
dynamicAttributeExtractor
public
CacheConfiguration
dynamicAttributeExtractor
(
DynamicAttributesExtractor
extractor)
Sets dynamic search attributes extractor
getCopyStrategyConfiguration
public
CopyStrategyConfiguration
getCopyStrategyConfiguration
()
Returns the copyStrategyConfiguration
getElementValueComparatorConfiguration
public
ElementValueComparatorConfiguration
getElementValueComparatorConfiguration
()
Returns the elementComparatorConfiguration
addCacheEventListenerFactory
public final void
addCacheEventListenerFactory
(
CacheConfiguration.CacheEventListenerFactoryConfiguration
factory)
Used by BeanUtils to add cacheEventListenerFactory elements to the cache configuration.
addCacheExtensionFactory
public final void
addCacheExtensionFactory
(
CacheConfiguration.CacheExtensionFactoryConfiguration
factory)
Used by BeanUtils to add cacheExtensionFactory elements to the cache configuration.
addBootstrapCacheLoaderFactory
public final void
addBootstrapCacheLoaderFactory
(
CacheConfiguration.BootstrapCacheLoaderFactoryConfiguration
factory)
Allows BeanHandler to add the CacheManagerEventListener to the configuration.
addCacheExceptionHandlerFactory
public final void
addCacheExceptionHandlerFactory
(
CacheConfiguration.CacheExceptionHandlerFactoryConfiguration
factory)
Add the CacheExceptionHandlerFactory to the configuration.
Note that this will not have any effect when creating a cache solely through its constructed. The exception
handler will only be taken into account when
ConfigurationHelper
is used, for example through
CacheManager
.
addCacheLoaderFactory
public final void
addCacheLoaderFactory
(
CacheConfiguration.CacheLoaderFactoryConfiguration
factory)
Used by BeanUtils to add each cacheLoaderFactory to the cache configuration.
addCacheDecoratorFactory
public final void
addCacheDecoratorFactory
(
CacheConfiguration.CacheDecoratorFactoryConfiguration
factory)
Used by BeanUtils to add each cacheDecoratorFactory to the cache configuration.
addTerracotta
public final void
addTerracotta
(
TerracottaConfiguration
terracottaConfiguration)
Allows BeanHandler to add the TerracottaConfiguration to the configuration.
addCacheWriter
public final void
addCacheWriter
(
CacheWriterConfiguration
cacheWriterConfiguration)
Allows BeanHandler to add the CacheWriterConfiguration to the configuration.
transactionalMode
public final
CacheConfiguration
transactionalMode
(
String
transactionalMode)
Builder which sets the transactionalMode
transactionalMode
public final
CacheConfiguration
transactionalMode
(
CacheConfiguration.TransactionalMode
transactionalMode)
Builder which sets the transactionalMode
getMemoryStoreEvictionPolicy
public
MemoryStoreEvictionPolicy
getMemoryStoreEvictionPolicy
()
Accessor
public boolean
isOverflowToDisk
()
Deprecated.
The
overflowToDisk
attribute has been replaced with
PersistenceConfiguration.Strategy.LOCALTEMPSWAP
.
Accessor
public boolean
isDiskPersistent
()
Deprecated.
The
diskPersistent
attribute has been replaced with
persistence(PersistenceConfiguration)
.
Accessor
getSizeOfPolicyConfiguration
public
SizeOfPolicyConfiguration
getSizeOfPolicyConfiguration
()
Accessor
getPersistenceConfiguration
public
PersistenceConfiguration
getPersistenceConfiguration
()
Accessor
getCacheDecoratorConfigurations
public
List
<
CacheConfiguration.CacheDecoratorFactoryConfiguration
>
getCacheDecoratorConfigurations
()
Accessor
getBootstrapCacheLoaderFactoryConfiguration
public
CacheConfiguration.BootstrapCacheLoaderFactoryConfiguration
getBootstrapCacheLoaderFactoryConfiguration
()
Accessor
getCacheExceptionHandlerFactoryConfiguration
public
CacheConfiguration.CacheExceptionHandlerFactoryConfiguration
getCacheExceptionHandlerFactoryConfiguration
()
Accessor
getCacheWriterConfiguration
public
CacheWriterConfiguration
getCacheWriterConfiguration
()
Accessor
getTerracottaConsistency
public
TerracottaConfiguration.Consistency
getTerracottaConsistency
()
Accessor
getTransactionalMode
public final
CacheConfiguration.TransactionalMode
getTransactionalMode
()
To what transactionalMode was the Cache set
addConfigurationListener
public boolean
addConfigurationListener
(
CacheConfigurationListener
listener)
Add a listener to this cache configuration
addDynamicSearchListener
public boolean
addDynamicSearchListener
(
DynamicSearchListener
listener)
Add a dynamic extractor configuration listener
removeConfigurationListener
public boolean
removeConfigurationListener
(
CacheConfigurationListener
listener)
Remove the supplied cache configuration listener.
public void
internalSetTimeToIdle
(long timeToIdle)
Intended for internal use only, and subject to change.
This is required so that changes in store implementation's config
(probably from other nodes) can propagate up to here