From b928953ced6cfbf0a708167195bacc166a70fa11 Mon Sep 17 00:00:00 2001 From: daguimu Date: Thu, 26 Mar 2026 09:46:35 +0800 Subject: [PATCH] Fix inconsistent weigher() javadoc in CacheBuilder. 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 #1690 --- .../guava/src/com/google/common/cache/CacheBuilder.java | 8 ++++---- guava/src/com/google/common/cache/CacheBuilder.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/android/guava/src/com/google/common/cache/CacheBuilder.java b/android/guava/src/com/google/common/cache/CacheBuilder.java index 3df641fee180..5ca865928131 100644 --- a/android/guava/src/com/google/common/cache/CacheBuilder.java +++ b/android/guava/src/com/google/common/cache/CacheBuilder.java @@ -549,10 +549,10 @@ public CacheBuilder maximumWeight(long maximumWeight) { /** * Specifies the weigher to use in determining the weight of entries. Entry weight is taken into - * consideration by {@link #maximumWeight(long)} when determining which entries to evict, and use - * of this method requires a corresponding call to {@link #maximumWeight(long)} prior to calling - * {@link #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. + * consideration by {@link #maximumWeight(long)} when determining whether the cache is over + * capacity, and use of this method requires a corresponding call to {@link #maximumWeight(long)} + * prior to calling {@link #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). diff --git a/guava/src/com/google/common/cache/CacheBuilder.java b/guava/src/com/google/common/cache/CacheBuilder.java index 9e8adaf8e955..2c70c67e55f7 100644 --- a/guava/src/com/google/common/cache/CacheBuilder.java +++ b/guava/src/com/google/common/cache/CacheBuilder.java @@ -549,10 +549,10 @@ public CacheBuilder maximumWeight(long maximumWeight) { /** * Specifies the weigher to use in determining the weight of entries. Entry weight is taken into - * consideration by {@link #maximumWeight(long)} when determining which entries to evict, and use - * of this method requires a corresponding call to {@link #maximumWeight(long)} prior to calling - * {@link #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. + * consideration by {@link #maximumWeight(long)} when determining whether the cache is over + * capacity, and use of this method requires a corresponding call to {@link #maximumWeight(long)} + * prior to calling {@link #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).