K - types of keys used in the cacheV - types of values used in the cachepublic static class EvictableCache.Builder<K,V>
extends java.lang.Object
EvictableCache.| Constructor and Description |
|---|
Builder() |
| Modifier and Type | Method and Description |
|---|---|
<K,V> EvictableCache<K,V> |
build()
Build a new instance of the cache based on configuration of this builder.
|
EvictableCache.Builder<K,V> |
cacheEnabled(boolean cacheEnabled)
If the cacheEnabled is set to false, no caching will be done.
|
EvictableCache.Builder<K,V> |
evictor(java.util.function.BiFunction<K,V,java.lang.Boolean> evictor)
Configure evictor to check if a records is still valid.
|
EvictableCache.Builder<K,V> |
evictSchedule(long evictDelay,
long evictPeriod,
java.util.concurrent.TimeUnit evictTimeUnit)
Configure eviction scheduling.
|
EvictableCache.Builder<K,V> |
fromConfig(Config config)
Update this builder from configuration.
|
EvictableCache.Builder<K,V> |
maxSize(long cacheMaxSize)
Configure maximal cache size.
|
EvictableCache.Builder<K,V> |
parallelismThreshold(long parallelismThreshold)
Configure parallelism threshold.
|
EvictableCache.Builder<K,V> |
timeout(long timeout,
java.util.concurrent.TimeUnit timeoutUnit)
Configure record timeout since last modification.
|
public <K,V> EvictableCache<K,V> build()
K - key typeV - value typepublic EvictableCache.Builder<K,V> timeout(long timeout, java.util.concurrent.TimeUnit timeoutUnit)
timeout - timeout valuetimeoutUnit - timeout unitpublic EvictableCache.Builder<K,V> maxSize(long cacheMaxSize)
cacheMaxSize - maximal number of records to store in the cachepublic EvictableCache.Builder<K,V> evictSchedule(long evictDelay, long evictPeriod, java.util.concurrent.TimeUnit evictTimeUnit)
evictDelay - delay from the creation of the cache to first evictionevictPeriod - how often to evict recordsevictTimeUnit - time unit to use for these valuespublic EvictableCache.Builder<K,V> parallelismThreshold(long parallelismThreshold)
parallelismThreshold - see ConcurrentHashMap.forEachKey(long, Consumer)public EvictableCache.Builder<K,V> evictor(java.util.function.BiFunction<K,V,java.lang.Boolean> evictor)
ConcurrentHashMap.forEachKey(long, Consumer).
This is also called during all get and remove operations to only return valid records.evictor - evictor to use, return true for records that should be evicted, false for records
that should stay in cachepublic EvictableCache.Builder<K,V> cacheEnabled(boolean cacheEnabled)
cacheEnabled - whether to enable this cache or not (true - enabled by default)public EvictableCache.Builder<K,V> fromConfig(Config config)
| key | default value | description |
|---|---|---|
| cache-enabled | true | Set to false to fully disable caching (and ignore other parameters) |
| cache-timeout-millis | minutes | Timeout of records in the cache in milliseconds |
| cache-evict-delay-millis | minutes | How long to wait with eviction after the cache is created in milliseconds |
| cache-evict-period-millis | minutes | How often to evict records from the cache in milliseconds |
| parallelism-treshold | see
parallelismThreshold(long) | |
| evictor-class | A class that is instantiated and used as an evictor for this instance |
config - Config to use to load configuration options for this builderCopyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.