Fix inconsistent weigher() javadoc in CacheBuilder#8298
Fix inconsistent weigher() javadoc in CacheBuilder#8298daguimu wants to merge 1 commit intogoogle:masterfrom
Conversation
The weigher() javadoc stated that entry weight is used "when determining which entries to evict", but maximumWeight() javadoc correctly states that "weight is only used to determine whether the cache is over capacity; it has no effect on selecting which entry should be evicted next." The implementation confirms this: getNextEvictable() selects entries based on access recency (LRU), not weight. Updated the weigher() javadoc to say weight is used "when determining whether the cache is over capacity", consistent with maximumWeight(). Fixes google#1690
|
@ben-manes, looks like the Caffeine docs have the same inconsistency: |
|
That is a fair confusion, though "consideration" means its left to We did collaborate to investigate using the weight as part of the eviction decision and shared our findings (paper). There are some modest gains but also adds complexity wrt concurrency, and for an on-heap Java cache it was unclear how beneficial the enhancement would be in practice so we backlogged it. |
|
I think these two statements in particular are in conflict:
Maybe |
Problem
The
weigher()javadoc inCacheBuilderstates that entry weight is used "when determining which entries to evict", contradicting themaximumWeight()javadoc which correctly states that "weight is only used to determine whether the cache is over capacity; it has no effect on selecting which entry should be evicted next."Root Cause
The
weigher()javadoc was written with imprecise wording. The implementation inLocalCache.Segment.getNextEvictable()confirms that eviction candidate selection is based on access recency (LRU via theaccessQueue), not entry weight. Weight only affects whether the total capacity threshold has been exceeded, triggering eviction.Fix
weigher()javadoc to say weight is used "when determining whether the cache is over capacity" instead of "when determining which entries to evict"Impact
Javadoc-only change. No behavioral change. Resolves the documented inconsistency between
weigher()andmaximumWeight()javadoc.Fixes #1690