Package javax.cache
Interface CacheBuilder<K,V>
-
- Type Parameters:
K- the key typeV- the value type
- All Known Implementing Classes:
CacheBuilderImpl
public interface CacheBuilder<K,V>A CacheBuilder is used for creating Caches. A CacheBuilder is created byCacheManager.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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Cache<K,V>build()Create an instance of the namedCache.CacheBuilder<K,V>registerCacheEntryListener(CacheEntryListener<K,V> cacheEntryListener)Registers a listener.CacheBuilder<K,V>setCacheLoader(CacheLoader<K,? extends V> cacheLoader)Sets the cache loader.CacheBuilder<K,V>setCacheWriter(CacheWriter<? super K,? super V> cacheWriter)Sets the cache writer.CacheBuilder<K,V>setExpiry(CacheConfiguration.ExpiryType type, CacheConfiguration.Duration duration)Sets the cache expirationCacheBuilder<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 namedCache. 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.CacheException- if a cache with that name already exists or there was an error adding the cache to the CacheManager- See Also:
CacheManager.createCacheBuilder(String)
-
setCacheLoader
CacheBuilder<K,V> setCacheLoader(CacheLoader<K,? extends V> cacheLoader)
Sets the cache loader.- Parameters:
cacheLoader- the CacheLoader- Returns:
- the builder
- Throws:
NullPointerException- if cacheLoader is null.
-
setCacheWriter
CacheBuilder<K,V> setCacheWriter(CacheWriter<? super K,? super V> cacheWriter)
Sets 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)
Registers a listener. Can be invoked multiple times.- Parameters:
cacheEntryListener- the listener- 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 changedInvalidConfigurationException- 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 isolation level for this cachemode- - the mode (Local or XA) for this cache- Returns:
- the builder
- Throws:
IllegalArgumentException- if the cache does not support transactions, or an attempt is made to set the isolation level toIsolationLevel.NONEor the mode toMode.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. If so a CacheLoader should be configured.- Parameters:
readThrough- the value for readThrough- Returns:
- the builder
-
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
-
setExpiry
CacheBuilder<K,V> setExpiry(CacheConfiguration.ExpiryType type, CacheConfiguration.Duration duration)
Sets the cache expiration- Parameters:
type- whether based on creation/modification or last access timeduration- the amount of time- Returns:
- the builder
- Throws:
NullPointerException- if size is duration
-
-