Performs eviction if the segment is over capacity. Avoids flushing the entire cache if the newest entry exceeds the maximum weight all on its own. @param newest the most recently added entry
(ReferenceEntry<K, V> newest)
| 2747 | */ |
| 2748 | |
| 2749 | @GuardedBy("this") |
| 2750 | void evictEntries(ReferenceEntry<K, V> newest) { |
| 2751 | if (!map.evictsBySize()) { |
| 2752 | return; |
| 2753 | } |
| 2754 | drainRecencyQueue(); |
| 2755 | |
| 2756 | // If the newest entry by itself is too heavy for the segment, don't bother evicting |
| 2757 | // anything else, just that |
| 2758 | if (newest.getValueReference().getWeight() > maxSegmentWeight) { |
| 2759 | if (!removeEntry(newest, newest.getHash(), RemovalCause.SIZE)) { |
| 2760 | throw new AssertionError(); |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | while (totalWeight > maxSegmentWeight) { |
| 2765 | ReferenceEntry<K, V> e = getNextEvictable(); |
| 2766 | if (!removeEntry(e, e.getHash(), RemovalCause.SIZE)) { |
| 2767 | throw new AssertionError(); |
| 2768 | } |
| 2769 | } |
| 2770 | } |
| 2771 | |
| 2772 | // TODO(fry): instead implement this with an eviction head |
| 2773 |
no test coverage detected