Top Description Methods
com.github.benmanes.caffeine.cache

public Interface Weigher<K, V>

Additional top-level classes in compilation unit: SingletonWeigher, BoundedWeigher.

Known Direct Implementers
com.github.benmanes.caffeine.cache.SingletonWeigher, com.github.benmanes.caffeine.cache.BoundedWeigher, com.github.benmanes.caffeine.cache.Async.AsyncWeigher
Annotations
@FunctionalInterface
Type Parameters
<K>
the type of keys
<V>
the type of values
Static Imports
com.github.benmanes.caffeine.cache.Caffeine.requireArgument, java.util.Objects.requireNonNull

Calculates the weights of cache entries. The total weight threshold is used to determine when an eviction is required.
Author
[email protected] (Ben Manes)

Method Summary

Modifier and TypeMethod and Description
public static <
the type of keys
K
,
the type of values
V
>
Weigher<K, V>

Returns:

a weigher that enforces that the weight is non-negative
boundedWeigher
(Weigher<K, V>
the weigher to weighs the entry
delegate
)

Returns a weigher that enforces that the weight is non-negative.

public static <
the type of keys
K
,
the type of values
V
>
Weigher<K, V>

Returns:

a weigher where an entry has a weight of 1
singletonWeigher
()

Returns a weigher where an entry has a weight of 1.

public @NonNegative int

Returns:

the weight of the entry; must be non-negative
weigh
(K
the key to weigh
key
,
V
the value to weigh
value
)

Returns the weight of a cache entry.

Method Detail

boundedWeigherback to summary
public static <K, V> Weigher<K, V> boundedWeigher(Weigher<K, V> delegate)

Returns a weigher that enforces that the weight is non-negative.

Parameters
<K>
the type of keys
<V>
the type of values
delegate:Weigher<K, V>

the weigher to weighs the entry

Returns:Weigher<K, V>

a weigher that enforces that the weight is non-negative

singletonWeigherback to summary
public static <K, V> Weigher<K, V> singletonWeigher()

Returns a weigher where an entry has a weight of 1.

Parameters
<K>
the type of keys
<V>
the type of values
Returns:Weigher<K, V>

a weigher where an entry has a weight of 1

weighback to summary
public @NonNegative int weigh(K key, V value)

Returns the weight of a cache entry. There is no unit for entry weights; rather they are simply relative to each other.

Parameters
key:K

the key to weigh

value:V

the value to weigh

Returns:@NonNegative int

the weight of the entry; must be non-negative