javax.cache
Interface CacheBuilder<K,V>

Type Parameters:
K - the key type
V - the value type

public interface CacheBuilder<K,V>

A CacheBuilder is used for creating Caches. A CacheBuilder is created by CacheManager.createCacheBuilder(String) and is associated with that manager. Additional configuration methods may be available on a builder instance by casting to a concrete implementation.

Since:
1.0
Author:
Yannis Cosmadopoulos

Method Summary
 Cache<K,V> build()
          Create an instance of the named Cache.
 CacheBuilder<K,V> registerCacheEntryListener(CacheEntryListener<K,V> cacheEntryListener, NotificationScope scope, boolean synchronous)
          Registers a listener.
 CacheBuilder<K,V> setCacheLoader(CacheLoader<K,V> cacheLoader)
          Set the cache loader.
 CacheBuilder<K,V> setCacheWriter(CacheWriter<K,V> cacheWriter)
          Set the cache writer.
 CacheBuilder<K,V> setExpiry(CacheConfiguration.ExpiryType type, CacheConfiguration.Duration timeToLive)
          Sets the cache expiration
 CacheBuilder<K,V> setReadThrough(boolean readThrough)
          Sets whether the cache is a read-through cache.
 CacheBuilder<K,V> setStatisticsEnabled(boolean enableStatistics)
          Sets whether statistics gathering is enabled on this cache.
 CacheBuilder<K,V> setStoreByValue(boolean storeByValue)
          Sets whether the cache is store-by-value cache.
 CacheBuilder<K,V> setTransactionEnabled(IsolationLevel isolationLevel, Mode mode)
          Sets whether transaction are enabled for this cache.
 CacheBuilder<K,V> setWriteThrough(boolean writeThrough)
          Whether the cache is a write-through cache.
 

Method Detail

build

Cache<K,V> build()
Create an instance of the named Cache.

The Cache will be created, added to the caches controlled by its associated CacheManager and started. If there is an existing Cache of the same name associated with this CacheManager when build is invoked, the old Cache will be stopped.

Returns:
a new instance of the named cache
Throws:
InvalidConfigurationException - thrown if the configuration is invalid. Examples include if read through has been set to true but no cache loader is specified, or if no cache writer is specified but write through has been set.
See Also:
CacheManager.createCacheBuilder(String)

setCacheLoader

CacheBuilder<K,V> setCacheLoader(CacheLoader<K,V> cacheLoader)
Set the cache loader.

Parameters:
cacheLoader - the CacheLoader
Returns:
the builder
Throws:
NullPointerException - if cacheLoader is null.

setCacheWriter

CacheBuilder<K,V> setCacheWriter(CacheWriter<K,V> cacheWriter)
Set the cache writer.

Parameters:
cacheWriter - the CacheWriter
Returns:
the builder
Throws:
NullPointerException - if cacheWriter is null.

registerCacheEntryListener

CacheBuilder<K,V> registerCacheEntryListener(CacheEntryListener<K,V> cacheEntryListener,
                                             NotificationScope scope,
                                             boolean synchronous)
Registers a listener. Can be invoked multiple times.

Parameters:
cacheEntryListener - the listener
scope - the notification scope.
synchronous - whether to listener should be invoked synchronously
Returns:
the builder
Throws:
NullPointerException - if any of the arguments are null.

setStoreByValue

CacheBuilder<K,V> setStoreByValue(boolean storeByValue)
Sets whether the cache is store-by-value cache.

Parameters:
storeByValue - the value for storeByValue
Returns:
the builder
Throws:
IllegalStateException - if the configuration can no longer be changed
InvalidConfigurationException - if the cache does not support store by reference
See Also:
CacheConfiguration.isStoreByValue()

setTransactionEnabled

CacheBuilder<K,V> setTransactionEnabled(IsolationLevel isolationLevel,
                                        Mode mode)
Sets whether transaction are enabled for this cache.

Parameters:
isolationLevel - - the default isolation level of this cache
mode - - the mode (Local or XA) for this cache
Returns:
the builder
Throws:
InvalidConfigurationException - if the cache does not support transactions, or the isolation level IsolationLevel.TX_NONE
See Also:
CacheConfiguration.isTransactionEnabled()

setStatisticsEnabled

CacheBuilder<K,V> setStatisticsEnabled(boolean enableStatistics)
Sets whether statistics gathering is enabled on this cache.

Parameters:
enableStatistics - true to enable statistics, false to disable
Returns:
the builder
See Also:
CacheConfiguration.setStatisticsEnabled(boolean)

setReadThrough

CacheBuilder<K,V> setReadThrough(boolean readThrough)
Sets whether the cache is a read-through cache.

Parameters:
readThrough - the value for readThrough
Returns:
the builder
Throws:
IllegalStateException - if the configuration can no longer be changed
See Also:
CacheConfiguration.setReadThrough(boolean)

setWriteThrough

CacheBuilder<K,V> 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
Returns:
the builder
See Also:
CacheConfiguration.setWriteThrough(boolean)

setExpiry

CacheBuilder<K,V> setExpiry(CacheConfiguration.ExpiryType type,
                            CacheConfiguration.Duration timeToLive)
Sets the cache expiration

Parameters:
timeToLive - the time to live
Returns:
the builder
Throws:
NullPointerException - if size is timeToLive
See Also:
CacheConfiguration.setExpiry(javax.cache.CacheConfiguration.ExpiryType, javax.cache.CacheConfiguration.Duration)


Copyright © 2011. All Rights Reserved.