Specifies the weigher to use in determining the weight of entries. Entry weight is taken
into consideration by
#maximumWeight(long) when determining which entries to evict, and
use of this method requires a corresponding call to
#maximumWeight(long) prior to
calling
#build. Weights are measured and recorded when entries are inserted into the
cache, and are thus effectively static during the lifetime of a cache entry.
When the weight of an entry is zero it will not be considered for size-based eviction
(though it still may be evicted by other means).
Important note: Instead of returning this as a
CacheBuilderinstance, this method returns
CacheBuilder. From this point on, either the
original reference or the returned reference may be used to complete configuration and build
the cache, but only the "generic" one is type-safe. That is, it will properly prevent you from
building caches whose key or value types are incompatible with the types accepted by the
weigher already provided; the
CacheBuilder type cannot do this. For best results,
simply use the standard method-chaining idiom, as illustrated in the documentation at top,
configuring a
CacheBuilder and building your Cache all in a single statement.
Warning: if you ignore the above advice, and use this
CacheBuilder to build
a cache whose key or value type is incompatible with the weigher, you will likely experience
a
ClassCastException at some undefined point in the future.