Class LazyRemovalCache<K,V>

java.lang.Object
org.jgroups.blocks.LazyRemovalCache<K,V>

public class LazyRemovalCache<K,V> extends Object
Cache which doesn't remove elements on remove(), removeAll() or retainAll(), but only removes elements when a configurable size limit has been exceeded. In that case, all elements marked as removable and older than a configurable time are evicted. Elements are marked as removable by remove(), removeAll() and retainAll(). When an elements is marked as removable, but later reinserted, the mark is removed.
  • Field Details

    • map

      private final ConcurrentMap<K,LazyRemovalCache.Entry<V>> map
    • max_elements

      private final int max_elements
      Max number of elements, if exceeded, we remove all elements marked as removable and older than max_age ms
    • max_age

      private final long max_age
  • Constructor Details

    • LazyRemovalCache

      public LazyRemovalCache()
    • LazyRemovalCache

      public LazyRemovalCache(int max_elements, long max_age)
      Creates a new instance
      Parameters:
      max_elements - The max number of elements in the cache
      max_age - The max age (in ms) an entry can have before it is considered expired (and can be removed on the next sweep)
  • Method Details

    • add

      public boolean add(K key, V val)
    • addIfAbsent

      public boolean addIfAbsent(K key, V val)
    • addAll

      public void addAll(Map<K,V> m)
    • addAllIfAbsent

      public void addAllIfAbsent(Map<K,V> m)
    • entrySet

      public Set<Map.Entry<K,LazyRemovalCache.Entry<V>>> entrySet()
    • containsKey

      public boolean containsKey(K key)
    • containsKeys

      public boolean containsKeys(Collection<K> keys)
      Returns true if all of the keys in keys are present. Returns false if one or more of the keys are absent
    • get

      public V get(K key)
    • getByValue

      public K getByValue(V val)
      Returns a (non-removable) entry based on the value
    • remove

      public void remove(K key)
    • remove

      public void remove(K key, boolean force)
    • removeAll

      public void removeAll(Collection<K> keys)
    • removeAll

      public void removeAll(Collection<K> keys, boolean force)
    • clear

      public void clear(boolean force)
    • retainAll

      public void retainAll(Collection<K> keys)
    • retainAll

      public void retainAll(Collection<K> keys, boolean force)
    • keySet

      public Set<K> keySet()
    • values

      public Set<V> values()
    • valuesIterator

      public Iterable<LazyRemovalCache.Entry<V>> valuesIterator()
    • nonRemovedValues

      public Set<V> nonRemovedValues()
      Adds all value which have not been marked as removable to the returned set
      Returns:
    • contents

      public Map<K,V> contents()
    • contents

      public Map<K,V> contents(boolean skip_removed_values)
    • size

      public int size()
    • printCache

      public String printCache()
    • printCache

      public String printCache(LazyRemovalCache.Printable print_function)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • checkMaxSizeExceeded

      private void checkMaxSizeExceeded()
    • removeMarkedElements

      public void removeMarkedElements(boolean force)
      Removes elements marked as removable
      Parameters:
      force - If set to true, all elements marked as 'removable' will get removed, regardless of expiration
    • removeMarkedElements

      public void removeMarkedElements()
      Removes elements marked as removable
    • add

      protected boolean add(K key, V val, boolean if_absent)
    • addAll

      protected void addAll(Map<K,V> m, boolean if_absent)