Class EvictableCache.Builder<K,V>
- java.lang.Object
-
- io.helidon.security.providers.common.EvictableCache.Builder<K,V>
-
- Type Parameters:
K
- types of keys used in the cacheV
- types of values used in the cache
- All Implemented Interfaces:
Builder<EvictableCache<K,V>>
,Supplier<EvictableCache<K,V>>
- Enclosing interface:
- EvictableCache<K,V>
public static class EvictableCache.Builder<K,V> extends Object implements Builder<EvictableCache<K,V>>
Builder to create instances ofEvictableCache
using the default implementation backed by aConcurrentHashMap
.
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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>
config(Config config)
Update this builder from configuration.EvictableCache.Builder<K,V>
evictor(BiFunction<K,V,Boolean> evictor)
Configure evictor to check if a record is still valid.EvictableCache.Builder<K,V>
evictSchedule(long evictDelay, long evictPeriod, TimeUnit evictTimeUnit)
Configure eviction scheduling.EvictableCache.Builder<K,V>
maxSize(long cacheMaxSize)
Configure maximal cache size.EvictableCache.Builder<K,V>
overallTimeout(long timeout, TimeUnit timeoutUnit)
Configure record timeout since its creation.EvictableCache.Builder<K,V>
parallelismThreshold(long parallelismThreshold)
Configure parallelism threshold.EvictableCache.Builder<K,V>
timeout(long timeout, TimeUnit timeoutUnit)
Configure record timeout since last access.
-
-
-
Method Detail
-
build
public EvictableCache<K,V> build()
Build a new instance of the cache based on configuration of this builder.
-
timeout
public EvictableCache.Builder<K,V> timeout(long timeout, TimeUnit timeoutUnit)
Configure record timeout since last access.- Parameters:
timeout
- timeout valuetimeoutUnit
- timeout unit- Returns:
- updated builder instance
-
overallTimeout
public EvictableCache.Builder<K,V> overallTimeout(long timeout, TimeUnit timeoutUnit)
Configure record timeout since its creation.- Parameters:
timeout
- timeout valuetimeoutUnit
- timeout unit- Returns:
- updated builder instance
-
maxSize
public EvictableCache.Builder<K,V> maxSize(long cacheMaxSize)
Configure maximal cache size.- Parameters:
cacheMaxSize
- maximal number of records to store in the cache- Returns:
- updated builder instance
-
evictSchedule
public EvictableCache.Builder<K,V> evictSchedule(long evictDelay, long evictPeriod, TimeUnit evictTimeUnit)
Configure eviction scheduling.- Parameters:
evictDelay
- delay from the creation of the cache to first evictionevictPeriod
- how often to evict recordsevictTimeUnit
- time unit to use for these values- Returns:
- updated builder instance
-
parallelismThreshold
public EvictableCache.Builder<K,V> parallelismThreshold(long parallelismThreshold)
Configure parallelism threshold.- Parameters:
parallelismThreshold
- seeConcurrentHashMap.forEachKey(long, Consumer)
- Returns:
- updated builder instance
-
evictor
public EvictableCache.Builder<K,V> evictor(BiFunction<K,V,Boolean> evictor)
Configure evictor to check if a record is still valid. This should be a fast way to check, as it is happening in aConcurrentHashMap.forEachKey(long, Consumer)
. This is also called during all get and remove operations to only return valid records.- Parameters:
evictor
- evictor to use, returntrue
for records that should be evicted,false
for records that should stay in cache- Returns:
- updated builder instance
-
cacheEnabled
public EvictableCache.Builder<K,V> cacheEnabled(boolean cacheEnabled)
If the cacheEnabled is set to false, no caching will be done. Otherwise (default behavior) evictable caching will be used.- Parameters:
cacheEnabled
- whether to enable this cache or not (true - enabled by default)- Returns:
- updated builder instance
-
config
public EvictableCache.Builder<K,V> config(Config config)
Update this builder from configuration. Options expected under the current config node:Configuration parameters key default value description cache-enabled true Set to false to fully disable caching (and ignore other parameters) cache-timeout-millis 60L minutes Timeout of records in the cache in milliseconds cache-evict-delay-millis 1L minutes How long to wait with eviction after the cache is created in milliseconds cache-evict-period-millis 5L minutes How often to evict records from the cache in milliseconds parallelism-treshold 10000L see parallelismThreshold(long)
evictor-class A class that is instantiated and used as an evictor for this instance - Parameters:
config
- Config to use to load configuration options for this builder- Returns:
- updated builder instance
-
-