Interface CacheConfiguration.Builder<K,V>

Type Parameters:
K - the cache key type
V - the cache value type
Enclosing interface:
CacheConfiguration<K,V>

public static interface CacheConfiguration.Builder<K,V>
A builder of a Caffeine cache configuration.
Author:
Paul Ferraro
  • Method Details

    • withMaxWeight

      CacheConfiguration.Builder<K,V> withMaxWeight(long weight)
      Defines the maximum weight of entries in the cache
      Parameters:
      weight - the maximum weight.
      Returns:
      a reference to this builder
    • evictableWhen

      default CacheConfiguration.Builder<K,V> evictableWhen(Predicate<K> evictable)
      Defines a predicate indicating whether a given entry is evictable.
      Parameters:
      evictable - a predicate indicating whether a given entry is evictable.
      Returns:
      a reference to this builder
    • evictableWhen

      default CacheConfiguration.Builder<K,V> evictableWhen(BiPredicate<K,V> evictable)
      Defines a predicate indicating whether a given entry is evictable.
      Parameters:
      evictable - a predicate indicating whether a given entry is evictable.
      Returns:
      a reference to this builder
    • withWeight

      default CacheConfiguration.Builder<K,V> withWeight(ToIntBiFunction<K,V> weight)
      Defines a function used to determine the weight of a given cache entry.
      Parameters:
      weight - a function used to determine the weight of a given cache entry.
      Returns:
      a reference to this builder
    • withWeigher

      CacheConfiguration.Builder<K,V> withWeigher(com.github.benmanes.caffeine.cache.Weigher<K,V> weigher)
      Defines a weigher used to determine the weight a given cache entry.
      Parameters:
      weigher - a weigher used to determine the weight a given cache entry.
      Returns:
      a reference to this builder
    • evictAfter

      default CacheConfiguration.Builder<K,V> evictAfter(Duration idleTimeout)
      Defines a duration of time after which idle entries should be auto-evicted.
      Parameters:
      idleTimeout - a duration of time after which idle entries should be auto-evicted.
      Returns:
      a reference to this builder
    • evictAfter

      default CacheConfiguration.Builder<K,V> evictAfter(Function<V,Duration> idleTimeout)
      Defines a function returning the duration of time after which a given idle entry should be auto-evicted.
      Parameters:
      idleTimeout - a function returning the duration of time after which a given idle entry should be auto-evicted.
      Returns:
      a reference to this builder
    • evictAfter

      default CacheConfiguration.Builder<K,V> evictAfter(BiFunction<K,V,Duration> idleTimeout)
      Defines a function returning the duration of time after which a given idle entry should be auto-evicted.
      Parameters:
      idleTimeout - a function returning the duration of time after which a given idle entry should be auto-evicted.
      Returns:
      a reference to this builder
    • withExpiry

      CacheConfiguration.Builder<K,V> withExpiry(com.github.benmanes.caffeine.cache.Expiry<K,V> expiry)
      Defines the logic used to determine the duration of time after which a given idle entry should be auto-evicted.
      Parameters:
      expiry - the logic used to determine the duration of time after which a given idle entry should be auto-evicted.
      Returns:
      a reference to this builder
    • whenEvicted

      default CacheConfiguration.Builder<K,V> whenEvicted(BiConsumer<K,V> handler)
      Defines a consumer to be notified on entry eviction.
      Parameters:
      handler - an eviction handler
      Returns:
      a reference to this builder
    • whenEvicted

      CacheConfiguration.Builder<K,V> whenEvicted(com.github.benmanes.caffeine.cache.RemovalListener<K,V> listener)
      Defines a listener to be notified on entry eviction.
      Parameters:
      listener - an eviction listener
      Returns:
      a reference to this builder
    • whenRemoved

      default CacheConfiguration.Builder<K,V> whenRemoved(BiConsumer<K,V> handler)
      Defines a consumer to be notified on entry removal.
      Parameters:
      handler - a removal handler
      Returns:
      a reference to this builder
    • whenRemoved

      CacheConfiguration.Builder<K,V> whenRemoved(com.github.benmanes.caffeine.cache.RemovalListener<K,V> listener)
      Defines a listener to be notified on entry removal.
      Parameters:
      listener - a removal listener
      Returns:
      a reference to this builder
    • withExecutor

      default CacheConfiguration.Builder<K,V> withExecutor(ScheduledExecutorService executor)
      Defines an executor for use with time-based eviction.
      Parameters:
      executor - an executor for use with time-based eviction.
      Returns:
      a reference to this builder
    • withScheduler

      CacheConfiguration.Builder<K,V> withScheduler(com.github.benmanes.caffeine.cache.Scheduler scheduler)
      Defines a scheduler for use with time-based eviction.
      Parameters:
      scheduler - a scheduler for use with time-based eviction.
      Returns:
      a reference to this builder
    • build

      Builds a cache configuration.
      Returns:
      a cache configuration.