Class RangeCache<Key extends Comparable<Key>,Value extends io.netty.util.ReferenceCounted>
java.lang.Object
org.apache.bookkeeper.mledger.util.RangeCache<Key,Value>
- Type Parameters:
Key- Cache key. Needs to be ComparableValue- Cache value
public class RangeCache<Key extends Comparable<Key>,Value extends io.netty.util.ReferenceCounted>
extends Object
Special type of cache where get() and delete() operations can be done over a range of keys.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface of a object that is able to the extract the "timestamp" of the cached values.static interfaceInterface of a object that is able to the extract the "weight" (size/cost/space) of the cached values. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new RangeLruCache with default Weighter.RangeCache(RangeCache.Weighter<Value> weighter, RangeCache.TimestampExtractor<Value> timestampExtractor) Construct a new RangeLruCache. -
Method Summary
Modifier and TypeMethodDescriptionclear()Remove all the entries from the cache.evictLeastAccessedEntries(long minSize) evictLEntriesBeforeTimestamp(long maxTimestamp) booleanprotected longJust for testing.longgetSize()booleanInsert.removeRange(Key first, Key last, boolean lastInclusive)
-
Constructor Details
-
RangeCache
public RangeCache()Construct a new RangeLruCache with default Weighter. -
RangeCache
public RangeCache(RangeCache.Weighter<Value> weighter, RangeCache.TimestampExtractor<Value> timestampExtractor) Construct a new RangeLruCache.- Parameters:
weighter- a custom weighter to compute the size of each stored value
-
-
Method Details
-
put
Insert.- Parameters:
key-value- ref counted value with at least 1 ref to pass on the cache- Returns:
- whether the entry was inserted in the cache
-
exists
-
get
-
getRange
- Parameters:
first- the first key in the rangelast- the last key in the range (inclusive)- Returns:
- a collections of the value found in cache
-
removeRange
public org.apache.commons.lang3.tuple.Pair<Integer,Long> removeRange(Key first, Key last, boolean lastInclusive) - Parameters:
first-last-lastInclusive-- Returns:
- an pair of ints, containing the number of removed entries and the total size
-
evictLeastAccessedEntries
- Parameters:
minSize-- Returns:
- a pair containing the number of entries evicted and their total size
-
evictLEntriesBeforeTimestamp
public org.apache.commons.lang3.tuple.Pair<Integer,Long> evictLEntriesBeforeTimestamp(long maxTimestamp) - Parameters:
maxTimestamp- the max timestamp of the entries to be evicted- Returns:
- the tota
-
getNumberOfEntries
protected long getNumberOfEntries()Just for testing. Getting the number of entries is very expensive on the conncurrent map -
getSize
public long getSize() -
clear
Remove all the entries from the cache.- Returns:
- size of removed entries
-