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 Comparable
Value - 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.
  • 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

      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
    • exists

      public boolean exists(Key key)
    • get

      public Value get(Key key)
    • getRange

      public Collection<Value> getRange(Key first, Key last)
      Parameters:
      first - the first key in the range
      last - 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

      public org.apache.commons.lang3.tuple.Pair<Integer,Long> evictLeastAccessedEntries(long minSize)
      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

      public org.apache.commons.lang3.tuple.Pair<Integer,Long> clear()
      Remove all the entries from the cache.
      Returns:
      size of removed entries