Interface CacheConfiguration.Builder<K,V>
- Type Parameters:
K- the cache key typeV- 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 Summary
Modifier and TypeMethodDescriptionbuild()Builds a cache configuration.default CacheConfiguration.Builder<K, V> evictableWhen(BiPredicate<K, V> evictable) Defines a predicate indicating whether a given entry is evictable.default CacheConfiguration.Builder<K, V> evictableWhen(Predicate<K> evictable) Defines a predicate indicating whether a given entry is evictable.default CacheConfiguration.Builder<K, V> evictAfter(Duration idleTimeout) Defines a duration of time after which idle entries should be auto-evicted.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.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.whenEvicted(com.github.benmanes.caffeine.cache.RemovalListener<K, V> listener) Defines a listener to be notified on entry eviction.default CacheConfiguration.Builder<K, V> whenEvicted(BiConsumer<K, V> handler) Defines a consumer to be notified on entry eviction.whenRemoved(com.github.benmanes.caffeine.cache.RemovalListener<K, V> listener) Defines a listener to be notified on entry removal.default CacheConfiguration.Builder<K, V> whenRemoved(BiConsumer<K, V> handler) Defines a consumer to be notified on entry removal.default CacheConfiguration.Builder<K, V> withExecutor(ScheduledExecutorService executor) Defines an executor for use with time-based eviction.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.withMaxWeight(long weight) Defines the maximum weight of entries in the cachewithScheduler(com.github.benmanes.caffeine.cache.Scheduler scheduler) Defines a scheduler for use with time-based eviction.withWeigher(com.github.benmanes.caffeine.cache.Weigher<K, V> weigher) Defines a weigher used to determine the weight a given cache entry.default CacheConfiguration.Builder<K, V> withWeight(ToIntBiFunction<K, V> weight) Defines a function used to determine the weight of a given cache entry.
-
Method Details
-
withMaxWeight
Defines the maximum weight of entries in the cache- Parameters:
weight- the maximum weight.- Returns:
- a reference to this builder
-
evictableWhen
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
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
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
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
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
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
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
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
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
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
-