/** * * @param minSize * @return a pair containing the number of entries evicted and their total size */ public Pair<Integer, Long> evictLeastAccessedEntries(long minSize) { checkArgument(minSize > 0); long removedSize = 0; int removedEntries = 0; while (removedSize < minSize) { Map.Entry<Key, Value> entry = entries.pollFirstEntry(); if (entry == null) { break; } Value value = entry.getValue(); ++removedEntries; removedSize += weighter.getSize(value); value.release(); } size.addAndGet(-removedSize); return Pair.of(removedEntries, removedSize); }
/** * * @param first * @param last * @param lastInclusive * @return an pair of ints, containing the number of removed entries and the total size */ public Pair<Integer, Long> removeRange(Key first, Key last, boolean lastInclusive) { Map<Key, Value> subMap = entries.subMap(first, true, last, lastInclusive); int removedEntries = 0; long removedSize = 0; for (Key key : subMap.keySet()) { Value value = entries.remove(key); if (value == null) { continue; } removedSize += weighter.getSize(value); value.release(); ++removedEntries; } size.addAndGet(-removedSize); return Pair.of(removedEntries, removedSize); }
/** * * @param first * @param last * @param lastInclusive * @return an pair of ints, containing the number of removed entries and the total size */ public Pair<Integer, Long> removeRange(Key first, Key last, boolean lastInclusive) { Map<Key, Value> subMap = entries.subMap(first, true, last, lastInclusive); int removedEntries = 0; long removedSize = 0; for (Key key : subMap.keySet()) { Value value = entries.remove(key); if (value == null) { continue; } removedSize += weighter.getSize(value); value.release(); ++removedEntries; } size.addAndGet(-removedSize); return Pair.create(removedEntries, removedSize); }
/** * * @param minSize * @return a pair containing the number of entries evicted and their total size */ public Pair<Integer, Long> evictLeastAccessedEntries(long minSize) { checkArgument(minSize > 0); long removedSize = 0; int removedEntries = 0; while (removedSize < minSize) { Map.Entry<Key, Value> entry = entries.pollFirstEntry(); if (entry == null) { break; } Value value = entry.getValue(); ++removedEntries; removedSize += weighter.getSize(value); value.release(); } size.addAndGet(-removedSize); return Pair.of(removedEntries, removedSize); }
/** * * @param minSize * @return a pair containing the number of entries evicted and their total size */ public Pair<Integer, Long> evictLeastAccessedEntries(long minSize) { checkArgument(minSize > 0); long removedSize = 0; int removedEntries = 0; while (removedSize < minSize) { Map.Entry<Key, Value> entry = entries.pollFirstEntry(); if (entry == null) { break; } Value value = entry.getValue(); ++removedEntries; removedSize += weighter.getSize(value); value.release(); } size.addAndGet(-removedSize); return Pair.create(removedEntries, removedSize); }
/** * Remove all the entries from the cache * * @return the old size */ public synchronized long clear() { long removedSize = 0; while (true) { Map.Entry<Key, Value> entry = entries.pollFirstEntry(); if (entry == null) { break; } Value value = entry.getValue(); removedSize += weighter.getSize(value); value.release(); } entries.clear(); return size.getAndAdd(-removedSize); }
/** * Remove all the entries from the cache. * * @return the old size */ public synchronized long clear() { long removedSize = 0; while (true) { Map.Entry<Key, Value> entry = entries.pollFirstEntry(); if (entry == null) { break; } Value value = entry.getValue(); removedSize += weighter.getSize(value); value.release(); } entries.clear(); return size.getAndAdd(-removedSize); }
/** * Insert. * * @param key * @param value * ref counted value with at least 1 ref to pass on the cache * @return whether the entry was inserted in the cache */ public boolean put(Key key, Value value) { if (entries.putIfAbsent(key, value) == null) { size.addAndGet(weighter.getSize(value)); return true; } else { return false; } }
/** * Insert * * @param key * @param value * ref counted value with at least 1 ref to pass on the cache * @return whether the entry was inserted in the cache */ public boolean put(Key key, Value value) { if (entries.putIfAbsent(key, value) == null) { size.addAndGet(weighter.getSize(value)); return true; } else { return false; } }
/** * * @param first * @param last * @param lastInclusive * @return an pair of ints, containing the number of removed entries and the total size */ public Pair<Integer, Long> removeRange(Key first, Key last, boolean lastInclusive) { Map<Key, Value> subMap = entries.subMap(first, true, last, lastInclusive); int removedEntries = 0; long removedSize = 0; for (Key key : subMap.keySet()) { Value value = entries.remove(key); if (value == null) { continue; } removedSize += weighter.getSize(value); value.release(); ++removedEntries; } size.addAndGet(-removedSize); return Pair.of(removedEntries, removedSize); }
/** * Remove all the entries from the cache. * * @return the old size */ public synchronized long clear() { long removedSize = 0; while (true) { Map.Entry<Key, Value> entry = entries.pollFirstEntry(); if (entry == null) { break; } Value value = entry.getValue(); removedSize += weighter.getSize(value); value.release(); } entries.clear(); return size.getAndAdd(-removedSize); }
/** * Insert. * * @param key * @param value * ref counted value with at least 1 ref to pass on the cache * @return whether the entry was inserted in the cache */ public boolean put(Key key, Value value) { if (entries.putIfAbsent(key, value) == null) { size.addAndGet(weighter.getSize(value)); return true; } else { return false; } }