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 cache
V - 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 Details

    • Builder

      public Builder()
  • Method Details

    • build

      public EvictableCache<K,V> build()
      Build a new instance of the cache based on configuration of this builder.
      Specified by:
      build in interface Builder<K,V>
      Returns:
      a new instance of the cache
    • timeout

      public EvictableCache.Builder<K,V> timeout(long timeout, TimeUnit timeoutUnit)
      Configure record timeout since last access.
      Parameters:
      timeout - timeout value
      timeoutUnit - 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 value
      timeoutUnit - 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 eviction
      evictPeriod - how often to evict records
      evictTimeUnit - 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 - see ConcurrentHashMap.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 a ConcurrentHashMap.forEachKey(long, Consumer). This is also called during all get and remove operations to only return valid records.
      Parameters:
      evictor - evictor to use, return true 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
      keydefault valuedescription
      cache-enabledtrueSet to false to fully disable caching (and ignore other parameters)
      cache-timeout-millis60L<K,V> minutesTimeout of records in the cache in milliseconds
      cache-evict-delay-millis1L<K,V> minutesHow long to wait with eviction after the cache is created in milliseconds
      cache-evict-period-millis5L<K,V> minutesHow often to evict records from the cache in milliseconds
      parallelism-treshold10000L<K,V>see parallelismThreshold(long)
      evictor-classA 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