K - Key typeV - Value typepublic class Builder<K,V> extends Object implements TriavaCacheConfiguration<K,V,Builder<K,V>>
TriavaCacheConfiguration.PropsType| Constructor and Description |
|---|
Builder()
Native Builder for creating Cache instances.
|
Builder(javax.cache.configuration.Configuration<K,V> configuration)
A Builder that is target for usage in JSR107 scenarios.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCacheEntryListenerConfiguration(javax.cache.configuration.CacheEntryListenerConfiguration<K,V> listenerConfiguration) |
Properties |
asProperties(TriavaCacheConfiguration.PropsType propsType)
Returns a representation of the Configuration as Properties.
|
Cache<K,V> |
build()
Builds a Cache from the parameters that were set. evictionType defines the eviction policy.
|
boolean |
equals(Object obj) |
Iterable<javax.cache.configuration.CacheEntryListenerConfiguration<K,V>> |
getCacheEntryListenerConfigurations() |
javax.cache.configuration.Factory<javax.cache.integration.CacheLoader<K,V>> |
getCacheLoaderFactory() |
CacheWriteMode |
getCacheWriteMode() |
javax.cache.configuration.Factory<javax.cache.integration.CacheWriter<? super K,? super V>> |
getCacheWriterFactory() |
long |
getCleanUpIntervalMillis()
Returns the proposed cleanup interval in ms.
|
int |
getConcurrencyLevel() |
EvictionInterface<K,V> |
getEvictionClass() |
EvictionPolicy |
getEvictionPolicy() |
javax.cache.configuration.Factory<javax.cache.expiry.ExpiryPolicy> |
getExpiryPolicyFactory() |
HashImplementation |
getHashImplementation() |
String |
getId() |
JamPolicy |
getJamPolicy() |
Class<K> |
getKeyType() |
CacheLoader<K,V> |
getLoader() |
int |
getMapConcurrencyLevel() |
long |
getMaxCacheTime() |
long |
getMaxCacheTimeSpread() |
int |
getMaxElements() |
long |
getMaxIdleTime() |
boolean |
getStatistics()
Returns whether statistics are enabled
|
Class<V> |
getValueType() |
int |
hashCode() |
boolean |
isManagementEnabled() |
boolean |
isReadThrough() |
boolean |
isStatisticsEnabled() |
boolean |
isStoreByValue() |
boolean |
isStrictJSR107()
Returns whether the Cache behaves strictly JSR107 compliant
|
boolean |
isWriteThrough() |
void |
removeCacheEntryListenerConfiguration(javax.cache.configuration.CacheEntryListenerConfiguration<K,V> listenerConfiguration) |
Builder<K,V> |
setCacheLoaderFactory(javax.cache.configuration.Factory<javax.cache.integration.CacheLoader<K,V>> loaderFactory) |
Builder<K,V> |
setCacheWriteMode(CacheWriteMode writeMode) |
Builder<K,V> |
setCacheWriterFactory(javax.cache.configuration.Factory<? extends javax.cache.integration.CacheWriter<? super K,? super V>> factory) |
Builder<K,V> |
setCleanupInterval(int cleanupInterval,
TimeUnit timeUnit)
Sets the proposed cleanup interval for expiring cache entries.
|
Builder<K,V> |
setConcurrencyLevel(int concurrencyLevel)
Sets the expected concurrency level.
|
Builder<K,V> |
setEvictionClass(EvictionInterface<K,V> clazz)
Sets a custom eviction policy.
|
Builder<K,V> |
setEvictionPolicy(EvictionPolicy evictionPolicy)
Sets the eviction policy, for example LFU or LRU.
|
Builder<K,V> |
setExpectedMapSize(int maxElements)
Deprecated.
|
Builder<K,V> |
setExpiryPolicyFactory(javax.cache.configuration.Factory<? extends javax.cache.expiry.ExpiryPolicy> factory)
Sets the ExpiryPolicyFactory.
|
Builder<K,V> |
setHashImplementation(HashImplementation hashImplementation)
Set the StorageBackend for the underlying ConcurrentMap.
|
Builder<K,V> |
setId(String id)
Sets the id of this Cache.
|
Builder<K,V> |
setJamPolicy(JamPolicy jamPolicy)
Sets the policy, how a Thread that calls put() will behave the cache is full.
|
void |
setKeyType(Class<K> keyType) |
Builder<K,V> |
setLoader(CacheLoader<K,V> loader) |
Builder<K,V> |
setManagement(boolean management)
Sets whether management should be enabled.
|
Builder<K,V> |
setMaxCacheTime(int maxCacheTime,
int interval,
TimeUnit timeUnit)
Sets the interval within a cache entry expires.
|
Builder<K,V> |
setMaxCacheTime(int maxCacheTime,
TimeUnit timeUnit)
Sets the default expiration time for entries in this cache.
|
Builder<K,V> |
setMaxElements(int maxElements)
Sets the expected number of elements to be stored.
|
Builder<K,V> |
setMaxIdleTime(int maxIdleTime,
TimeUnit timeUnit)
Sets the maximum time of an unused (idle) cache entry.
|
Builder<K,V> |
setReadThrough(boolean isReadThrough) |
Builder<K,V> |
setStatistics(boolean statistics)
Sets whether statistics should be gathered.
|
void |
setStrictJSR107(boolean strictJSR107) |
void |
setValueType(Class<V> valueType) |
Builder<K,V> |
setWriteThrough(boolean isWriteThrough) |
StorageBackend<K,V> |
storageFactory() |
public Builder()
Any Cache created by build() is registered in the given factory/CacheManager.
public Builder(javax.cache.configuration.Configuration<K,V> configuration)
CacheWriteMode.fromStoreByValue(boolean).
Defaults for this Builder are taken from the given configuration, which can be a plain JSR107 Configuration or a Builder itself. The given configuration is copied in both cases, so subsequent changes to the original object will have no effect on this Builder or any Cache created from it.
Any Cache created by build() is registered in the given factory/CacheManager.
configuration - Cache Configuration, which can also be a Builderpublic Cache<K,V> build()
private long maxIdleTime = 1800; private long maxCacheTime = 3600; private int expectedMapSize = 10000; private int concurrencyLevel = 16; private TCacheEvictionType evictionType = TCacheEvictionType.LFU;Any Cache created by
build() is registered in the associated factory/CacheManager.public Builder<K,V> setId(String id)
TriavaCacheConfigurationpublic Builder<K,V> setMaxIdleTime(int maxIdleTime, TimeUnit timeUnit)
TriavaCacheConfigurationTriavaCacheConfiguration.setExpiryPolicyFactory(Factory).setMaxIdleTime in interface TriavaCacheConfiguration<K,V,Builder<K,V>>maxIdleTime - The maximum timetimeUnit - The TimeUnit of maxIdleTimepublic Builder<K,V> setMaxCacheTime(int maxCacheTime, int interval, TimeUnit timeUnit)
TriavaCacheConfigurationThis method is useful for mass-inserts in the Cache, that should not expire at the same time (e.g. for resource reasons).
setMaxCacheTime in interface TriavaCacheConfiguration<K,V,Builder<K,V>>maxCacheTime - The minimum time to keep in secondsinterval - The size of the interval in secondstimeUnit - The TimeUnit of maxCacheTime and intervalpublic Builder<K,V> setMaxCacheTime(int maxCacheTime, TimeUnit timeUnit)
TriavaCacheConfigurationCache.put(Object, Object, int, int, TimeUnit).setMaxCacheTime in interface TriavaCacheConfiguration<K,V,Builder<K,V>>maxCacheTime - The time to keep the value in secondstimeUnit - The TimeUnit of maxCacheTimepublic Builder<K,V> setCleanupInterval(int cleanupInterval, TimeUnit timeUnit)
TriavaCacheConfiguration
If you do not call this method, the default
cleanup interval is used. For JSR107 Caches this is 1 minute. For native Triava Caches this
is auto-optimized according to a fraction of TriavaCacheConfiguration.getMaxIdleTime().
setCleanupInterval in interface TriavaCacheConfiguration<K,V,Builder<K,V>>cleanupInterval - The eviction cleanup interval. 0 means auto-tuning.timeUnit - The TimeUnit of cleanupIntervalpublic Builder<K,V> setExpectedMapSize(int maxElements)
setMaxElements(int)maxElements - See setMaxElements(int)public Builder<K,V> setMaxElements(int maxElements)
TriavaCacheConfigurationTriavaCacheConfiguration.getMaxElements(). Cache instances of unlimited size
EvictionPolicy.NONE will use this value only as a hint
for initially sizing the underlying storage structures.setMaxElements in interface TriavaCacheConfiguration<K,V,Builder<K,V>>maxElements - The maximum number of elements to be storedpublic Builder<K,V> setConcurrencyLevel(int concurrencyLevel)
TriavaCacheConfigurationIf not set, the default concurrencyLevel is 16, which should usually rarely create thread contention. If running with 12 cores (24 with hyperthreading) chances are not too high for contention. A note from the Java 6 API docs: "overestimates and underestimates within an order of magnitude do not usually have much noticeable impact."
For example, in a scenario where 150 Threads write concurrently via putIfAbsent(), only 12 Threads will actually run. As concurrencyLevel is 16, threads will usually rarely block. But in case of unlucky hash bucket distribution or if too many Threads get suspended during holding a lock, issues could arise. If the underlying ConcurrentMap uses unfair locks, it might even lead to thread starvation.
setConcurrencyLevel in interface TriavaCacheConfiguration<K,V,Builder<K,V>>concurrencyLevel - The excpected number of application Threads that concurrently write to the Cachepublic Builder<K,V> setEvictionPolicy(EvictionPolicy evictionPolicy)
TriavaCacheConfiguration
If you want to use a custom eviction strategy,
use TriavaCacheConfiguration.setEvictionClass(EvictionInterface) instead.
setEvictionPolicy in interface TriavaCacheConfiguration<K,V,Builder<K,V>>evictionPolicy - The EvictionPolicypublic Builder<K,V> setEvictionClass(EvictionInterface<K,V> clazz)
TriavaCacheConfiguration
If you want to use a standard eviction strategy like LFU or LRU,
use TriavaCacheConfiguration.setEvictionPolicy(EvictionPolicy) instead.
setEvictionClass in interface TriavaCacheConfiguration<K,V,Builder<K,V>>clazz - The instance that implements the eviction policypublic EvictionInterface<K,V> getEvictionClass()
getEvictionClass in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public Builder<K,V> setHashImplementation(HashImplementation hashImplementation)
setHashImplementation in interface TriavaCacheConfiguration<K,V,Builder<K,V>>hashImplementation - The HashImplementationpublic Builder<K,V> setJamPolicy(JamPolicy jamPolicy)
JamPolicy has no effect on caches of unlimited size
EvictionPolicy}.NONE.setJamPolicy in interface TriavaCacheConfiguration<K,V,Builder<K,V>>jamPolicy - The JamPolicypublic boolean getStatistics()
TriavaCacheConfigurationgetStatistics in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public Builder<K,V> setStatistics(boolean statistics)
setStatistics in interface TriavaCacheConfiguration<K,V,Builder<K,V>>statistics - true, if you want to switch on statisticspublic Builder<K,V> setManagement(boolean management)
setManagement in interface TriavaCacheConfiguration<K,V,Builder<K,V>>management - true, if you want to switch on managementpublic String getId()
public long getMaxIdleTime()
getMaxIdleTime in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public long getMaxCacheTime()
getMaxCacheTime in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public long getMaxCacheTimeSpread()
getMaxCacheTimeSpread in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public long getCleanUpIntervalMillis()
setCleanupInterval(int, TimeUnit) for details on how the Cache uses this value.getCleanUpIntervalMillis in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public int getMaxElements()
getMaxElements in interface TriavaCacheConfiguration<K,V,Builder<K,V>>TriavaCacheConfiguration.setMaxElements(int)public int getConcurrencyLevel()
getConcurrencyLevel in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public int getMapConcurrencyLevel()
getMapConcurrencyLevel in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public EvictionPolicy getEvictionPolicy()
getEvictionPolicy in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public HashImplementation getHashImplementation()
getHashImplementation in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public StorageBackend<K,V> storageFactory()
storageFactory in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public JamPolicy getJamPolicy()
getJamPolicy in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public CacheLoader<K,V> getLoader()
public javax.cache.configuration.Factory<javax.cache.integration.CacheLoader<K,V>> getCacheLoaderFactory()
getCacheLoaderFactory in interface TriavaCacheConfiguration<K,V,Builder<K,V>>getCacheLoaderFactory in interface javax.cache.configuration.CompleteConfiguration<K,V>public Class<K> getKeyType()
getKeyType in interface TriavaCacheConfiguration<K,V,Builder<K,V>>getKeyType in interface javax.cache.configuration.Configuration<K,V>public Class<V> getValueType()
getValueType in interface TriavaCacheConfiguration<K,V,Builder<K,V>>getValueType in interface javax.cache.configuration.Configuration<K,V>public void setKeyType(Class<K> keyType)
setKeyType in interface TriavaCacheConfiguration<K,V,Builder<K,V>>keyType - the required key typeTriavaCacheConfiguration.getKeyType()public void setValueType(Class<V> valueType)
setValueType in interface TriavaCacheConfiguration<K,V,Builder<K,V>>valueType - the required value typeTriavaCacheConfiguration.getValueType()public boolean isStoreByValue()
isStoreByValue in interface TriavaCacheConfiguration<K,V,Builder<K,V>>isStoreByValue in interface javax.cache.configuration.Configuration<K,V>public CacheWriteMode getCacheWriteMode()
getCacheWriteMode in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public Builder<K,V> setCacheWriteMode(CacheWriteMode writeMode)
setCacheWriteMode in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public Properties asProperties(TriavaCacheConfiguration.PropsType propsType)
asProperties in interface TriavaCacheConfiguration<K,V,Builder<K,V>>propsType - If PropsType.CacheManager, the Cache specific properties (cacheName, cacheLoaderClass) are excludedpublic int hashCode()
public boolean equals(Object obj)
public boolean isReadThrough()
isReadThrough in interface TriavaCacheConfiguration<K,V,Builder<K,V>>isReadThrough in interface javax.cache.configuration.CompleteConfiguration<K,V>public Builder<K,V> setCacheLoaderFactory(javax.cache.configuration.Factory<javax.cache.integration.CacheLoader<K,V>> loaderFactory)
setCacheLoaderFactory in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public Builder<K,V> setCacheWriterFactory(javax.cache.configuration.Factory<? extends javax.cache.integration.CacheWriter<? super K,? super V>> factory)
setCacheWriterFactory in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public Builder<K,V> setReadThrough(boolean isReadThrough)
setReadThrough in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public Builder<K,V> setWriteThrough(boolean isWriteThrough)
setWriteThrough in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public boolean isWriteThrough()
isWriteThrough in interface TriavaCacheConfiguration<K,V,Builder<K,V>>isWriteThrough in interface javax.cache.configuration.CompleteConfiguration<K,V>public boolean isStatisticsEnabled()
isStatisticsEnabled in interface TriavaCacheConfiguration<K,V,Builder<K,V>>isStatisticsEnabled in interface javax.cache.configuration.CompleteConfiguration<K,V>public boolean isManagementEnabled()
isManagementEnabled in interface TriavaCacheConfiguration<K,V,Builder<K,V>>isManagementEnabled in interface javax.cache.configuration.CompleteConfiguration<K,V>public boolean isStrictJSR107()
isStrictJSR107 in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public void setStrictJSR107(boolean strictJSR107)
setStrictJSR107 in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public Iterable<javax.cache.configuration.CacheEntryListenerConfiguration<K,V>> getCacheEntryListenerConfigurations()
getCacheEntryListenerConfigurations in interface TriavaCacheConfiguration<K,V,Builder<K,V>>getCacheEntryListenerConfigurations in interface javax.cache.configuration.CompleteConfiguration<K,V>public javax.cache.configuration.Factory<javax.cache.integration.CacheWriter<? super K,? super V>> getCacheWriterFactory()
getCacheWriterFactory in interface TriavaCacheConfiguration<K,V,Builder<K,V>>getCacheWriterFactory in interface javax.cache.configuration.CompleteConfiguration<K,V>public javax.cache.configuration.Factory<javax.cache.expiry.ExpiryPolicy> getExpiryPolicyFactory()
getExpiryPolicyFactory in interface TriavaCacheConfiguration<K,V,Builder<K,V>>getExpiryPolicyFactory in interface javax.cache.configuration.CompleteConfiguration<K,V>public Builder<K,V> setExpiryPolicyFactory(javax.cache.configuration.Factory<? extends javax.cache.expiry.ExpiryPolicy> factory)
setMaxIdleTime(int, TimeUnit).setExpiryPolicyFactory in interface TriavaCacheConfiguration<K,V,Builder<K,V>>factory - The factorypublic void addCacheEntryListenerConfiguration(javax.cache.configuration.CacheEntryListenerConfiguration<K,V> listenerConfiguration)
addCacheEntryListenerConfiguration in interface TriavaCacheConfiguration<K,V,Builder<K,V>>public void removeCacheEntryListenerConfiguration(javax.cache.configuration.CacheEntryListenerConfiguration<K,V> listenerConfiguration)
removeCacheEntryListenerConfiguration in interface TriavaCacheConfiguration<K,V,Builder<K,V>>Copyright © 2018 trivago. All rights reserved.