Class RangeCache<Key extends java.lang.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 java.lang.Comparable<Key>,Value extends io.netty.util.ReferenceCounted> extends java.lang.ObjectSpecial type of cache where get() and delete() operations can be done over a range of keys.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRangeCache.TimestampExtractor<ValueT>Interface of a object that is able to the extract the "timestamp" of the cached values.static interfaceRangeCache.Weighter<ValueT>Interface of a object that is able to the extract the "weight" (size/cost/space) of the cached values.
-
Constructor Summary
Constructors Constructor Description RangeCache()Construct a new RangeLruCache with default Weighter.RangeCache(RangeCache.Weighter<Value> weighter, RangeCache.TimestampExtractor<Value> timestampExtractor)Construct a new RangeLruCache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longclear()Remove all the entries from the cache.org.apache.commons.lang3.tuple.Pair<java.lang.Integer,java.lang.Long>evictLeastAccessedEntries(long minSize)longevictLEntriesBeforeTimestamp(long maxTimestamp)Valueget(Key key)protected longgetNumberOfEntries()Just for testing.java.util.Collection<Value>getRange(Key first, Key last)longgetSize()booleanput(Key key, Value value)Insert.org.apache.commons.lang3.tuple.Pair<java.lang.Integer,java.lang.Long>removeRange(Key first, Key last, boolean lastInclusive)
-
-
-
Constructor Detail
-
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 Detail
-
put
public boolean put(Key key, Value value)
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
-
getRange
public java.util.Collection<Value> getRange(Key first, Key last)
- 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<java.lang.Integer,java.lang.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
public org.apache.commons.lang3.tuple.Pair<java.lang.Integer,java.lang.Long> evictLeastAccessedEntries(long minSize)
- Parameters:
minSize-- Returns:
- a pair containing the number of entries evicted and their total size
-
evictLEntriesBeforeTimestamp
public 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
public long clear()
Remove all the entries from the cache.- Returns:
- size of removed entries
-
-