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. W
(
Weigher<? super K1, ? super V1> weigher)
| 485 | * @since 11.0 |
| 486 | */ |
| 487 | @GwtIncompatible // To be supported |
| 488 | public <K1 extends K, V1 extends V> CacheBuilder<K1, V1> weigher( |
| 489 | Weigher<? super K1, ? super V1> weigher) { |
| 490 | checkState(this.weigher == null); |
| 491 | if (strictParsing) { |
| 492 | checkState( |
| 493 | this.maximumSize == UNSET_INT, |
| 494 | "weigher can not be combined with maximum size", |
| 495 | this.maximumSize); |
| 496 | } |
| 497 | |
| 498 | // safely limiting the kinds of caches this can produce |
| 499 | @SuppressWarnings("unchecked") |
| 500 | CacheBuilder<K1, V1> me = (CacheBuilder<K1, V1>) this; |
| 501 | me.weigher = checkNotNull(weigher); |
| 502 | return me; |
| 503 | } |
| 504 | |
| 505 | long getMaximumWeight() { |
| 506 | if (expireAfterWriteNanos == 0 || expireAfterAccessNanos == 0) { |
no test coverage detected