Skip to content

Commit

Permalink
work around shortcircuited onRemoval notification for identical rep…
Browse files Browse the repository at this point in the history
…lacement values
  • Loading branch information
magibney committed Dec 9, 2024
1 parent 41aa2c5 commit c2abbc6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion solr/core/src/java/org/apache/solr/search/CaffeineCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,14 @@ public V put(K key, V val) {
inserts.increment();
V old = cache.asMap().put(key, val);
// ramBytes decrement for `old` happens via #onRemoval
recordRamBytes(key, null, val);
if (val != old) {
// NOTE: this is conditional on `val != old` in order to work around a
// behavior in the Caffeine library: where there is reference equality
// between `val` and `old`, caffeine does _not_ invoke RemovalListener,
// so the entry is not decremented for the replaced value (hence we
// don't need to increment ram bytes for the entry either).
recordRamBytes(key, null, val);
}
return old;
}

Expand Down

0 comments on commit c2abbc6

Please sign in to comment.