javax.cache
Interface CacheConfiguration


public interface CacheConfiguration

Information on how a cache is configured.

A Cache may be constructed by CacheManager using a configuration instance.

At runtime it is used by javax.cache to decide how to behave. For example the behaviour of put will vary depending on whether the cache is write-through.

Finally, a cache makes it's configuration visible via this interface. Only those configurations which can be changed at runtime (if supported by the underlying implementation) have setters in this interface. Those that can only be set prior to cache construction have setters in CacheBuilder.

Since:
1.0
Author:
Greg Luck, Yannis Cosmadopoulos

Nested Class Summary
static class CacheConfiguration.Duration
          A time duration.
static class CacheConfiguration.ExpiryType
          Type of Expiry
 
Method Summary
 CacheConfiguration.Duration getExpiry(CacheConfiguration.ExpiryType type)
          Gets the cache's time to live setting,Sets how long cache entries should live.
 IsolationLevel getTransactionIsolationLevel()
          Gets the transaction isolation level.
 Mode getTransactionMode()
          Gets the transaction mode.
 boolean isReadThrough()
          Whether the cache is a read-through cache.
 boolean isStatisticsEnabled()
          Checks whether statistics collection is enabled in this cache.
 boolean isStoreByValue()
          Whether storeByValue (true) or storeByReference (false).
 boolean isTransactionEnabled()
          Checks whether transaction are enabled for this cache.
 boolean isWriteThrough()
          Whether the cache is a write-through cache.
 void setExpiry(CacheConfiguration.ExpiryType type, CacheConfiguration.Duration duration)
          Sets how long cache entries should live.
 void setReadThrough(boolean readThrough)
          Sets whether the cache is a read-through cache.
 void setStatisticsEnabled(boolean enableStatistics)
          Sets whether statistics gathering is enabled on this cache.
 void setWriteThrough(boolean writeThrough)
          Whether the cache is a write-through cache.
 

Method Detail

isReadThrough

boolean isReadThrough()
Whether the cache is a read-through cache. A CacheLoader should be configured for read through caches which is called on a cache miss.

Default value is false.

Returns:
true if the cache is read-through

setReadThrough

void setReadThrough(boolean readThrough)
Sets whether the cache is a read-through cache.

Parameters:
readThrough - the value for readThrough
Throws:
IllegalStateException - if the configuration can no longer be changed

isWriteThrough

boolean isWriteThrough()
Whether the cache is a write-through cache. A CacheWriter should be configured.

Default value is false.

Returns:
true if the cache is write-through

setWriteThrough

void setWriteThrough(boolean writeThrough)
Whether the cache is a write-through cache. A CacheWriter should be configured.

Parameters:
writeThrough - set to true for a write-through cache

isStoreByValue

boolean isStoreByValue()
Whether storeByValue (true) or storeByReference (false). When true, both keys and values are stored by value.

When false, both keys and values are stored by reference. Caches stored by reference are capable of mutation by any threads holding the reference. The effects are:

Storage by reference only applies to local heap. If an entry is moved outside local heap it will need to be transformed into a representation. Any mutations that occur after transformation will not be reflected in the cache.

Default value is true.

Returns:
true if the cache is store by value

isStatisticsEnabled

boolean isStatisticsEnabled()
Checks whether statistics collection is enabled in this cache.

Default value is false.

Returns:
true if statistics collection is enabled

setStatisticsEnabled

void setStatisticsEnabled(boolean enableStatistics)
Sets whether statistics gathering is enabled on this cache.

Parameters:
enableStatistics - true to enable statistics, false to disable

isTransactionEnabled

boolean isTransactionEnabled()
Checks whether transaction are enabled for this cache.

Default value is false.

Returns:
true if transaction are enabled

getTransactionIsolationLevel

IsolationLevel getTransactionIsolationLevel()
Gets the transaction isolation level.

Returns:
the isolation level. null if this cache is not transactional

getTransactionMode

Mode getTransactionMode()
Gets the transaction mode.

Returns:
the the mode of the cache. null if this cache is not transactional

setExpiry

void setExpiry(CacheConfiguration.ExpiryType type,
               CacheConfiguration.Duration duration)
Sets how long cache entries should live. If expiry is not set entries are eternal. It both types of expiry are set, then each is checked. If expiry has occurred in either type then the entry is expired.

Any operation that accesses an expired entry will behave as if it is not in the cache. So:

Parameters:
type - the type of the expiry
duration - how long, in the specified duration, the cache entries should live.
Throws:
NullPointerException - is type or duration is null

getExpiry

CacheConfiguration.Duration getExpiry(CacheConfiguration.ExpiryType type)
Gets the cache's time to live setting,Sets how long cache entries should live. If expiry is not set entries are eternal.

Default value is CacheConfiguration.Duration.ETERNAL.

Parameters:
type - the type of the expiration
Returns:
how long, in milliseconds, the specified units, the entry should live. 0 means eternal.


Copyright © 2011. All Rights Reserved.