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.Builder<K,
,V>, EvictableCache<K, V>> Supplier<EvictableCache<K,
V>>
- Enclosing interface:
EvictableCache<K,
V>
public static class EvictableCache.Builder<K,V>
extends Object
implements Builder<EvictableCache.Builder<K,V>,EvictableCache<K,V>>
Builder to create instances of
EvictableCache
using the default implementation backed by
a ConcurrentHashMap
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build a new instance of the cache based on configuration of this builder.cacheEnabled
(boolean cacheEnabled) If the cacheEnabled is set to false, no caching will be done.Update this builder from configuration.evictor
(BiFunction<K, V, Boolean> evictor) Configure evictor to check if a record is still valid.evictSchedule
(long evictDelay, long evictPeriod, TimeUnit evictTimeUnit) Configure eviction scheduling.maxSize
(long cacheMaxSize) Configure maximal cache size.overallTimeout
(long timeout, TimeUnit timeoutUnit) Configure record timeout since its creation.parallelismThreshold
(long parallelismThreshold) Configure parallelism threshold.Configure record timeout since last access.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
build
Build a new instance of the cache based on configuration of this builder. -
timeout
Configure record timeout since last access.- Parameters:
timeout
- timeout valuetimeoutUnit
- timeout unit- Returns:
- updated builder instance
-
overallTimeout
Configure record timeout since its creation.- Parameters:
timeout
- timeout valuetimeoutUnit
- timeout unit- Returns:
- updated builder instance
-
maxSize
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
Configure parallelism threshold.- Parameters:
parallelismThreshold
- seeConcurrentHashMap.forEachKey(long, Consumer)
- Returns:
- updated builder instance
-
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
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
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<K, V> minutes Timeout of records in the cache in milliseconds cache-evict-delay-millis 1L<K, V> minutes How long to wait with eviction after the cache is created in milliseconds cache-evict-period-millis 5L<K, V> minutes How often to evict records from the cache in milliseconds parallelism-treshold 10000L<K, V> 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
-