Package org.jgroups.blocks
Class LazyRemovalCache<K,V>
- java.lang.Object
-
- org.jgroups.blocks.LazyRemovalCache<K,V>
-
public class LazyRemovalCache<K,V> extends java.lang.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.- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LazyRemovalCache.Entry<V>
static interface
LazyRemovalCache.Printable<K,V>
-
Constructor Summary
Constructors Constructor Description LazyRemovalCache()
LazyRemovalCache(int max_elements, long max_age)
Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(K key, V val)
protected boolean
add(K key, V val, boolean if_absent)
void
addAll(java.util.Map<K,V> m)
protected void
addAll(java.util.Map<K,V> m, boolean if_absent)
void
addAllIfAbsent(java.util.Map<K,V> m)
boolean
addIfAbsent(K key, V val)
void
clear(boolean force)
boolean
containsKey(K key)
boolean
containsKeys(java.util.Collection<K> keys)
Returns true if all of the keys in keys are present.java.util.Map<K,V>
contents()
java.util.Map<K,V>
contents(boolean skip_removed_values)
java.util.Set<java.util.Map.Entry<K,LazyRemovalCache.Entry<V>>>
entrySet()
V
get(K key)
K
getByValue(V val)
java.util.Set<K>
keySet()
java.util.Set<V>
nonRemovedValues()
Adds all value which have not been marked as removable to the returned setjava.lang.String
printCache()
java.lang.String
printCache(LazyRemovalCache.Printable print_function)
void
remove(K key)
void
remove(K key, boolean force)
void
removeAll(java.util.Collection<K> keys)
void
removeAll(java.util.Collection<K> keys, boolean force)
void
removeMarkedElements()
Removes elements marked as removablevoid
removeMarkedElements(boolean force)
Removes elements marked as removablevoid
retainAll(java.util.Collection<K> keys)
void
retainAll(java.util.Collection<K> keys, boolean force)
int
size()
java.lang.String
toString()
java.util.Set<V>
values()
java.lang.Iterable<LazyRemovalCache.Entry<V>>
valuesIterator()
-
-
-
Constructor Detail
-
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 cachemax_age
- The max age (in ms) an entry can have before it is considered expired (and can be removed on the next sweep)
-
-
Method Detail
-
entrySet
public java.util.Set<java.util.Map.Entry<K,LazyRemovalCache.Entry<V>>> entrySet()
-
containsKey
public boolean containsKey(K key)
-
containsKeys
public boolean containsKeys(java.util.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
-
remove
public void remove(K key)
-
remove
public void remove(K key, boolean force)
-
removeAll
public void removeAll(java.util.Collection<K> keys)
-
removeAll
public void removeAll(java.util.Collection<K> keys, boolean force)
-
clear
public void clear(boolean force)
-
retainAll
public void retainAll(java.util.Collection<K> keys)
-
retainAll
public void retainAll(java.util.Collection<K> keys, boolean force)
-
keySet
public java.util.Set<K> keySet()
-
values
public java.util.Set<V> values()
-
valuesIterator
public java.lang.Iterable<LazyRemovalCache.Entry<V>> valuesIterator()
-
nonRemovedValues
public java.util.Set<V> nonRemovedValues()
Adds all value which have not been marked as removable to the returned set- Returns:
-
size
public int size()
-
printCache
public java.lang.String printCache()
-
printCache
public java.lang.String printCache(LazyRemovalCache.Printable print_function)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
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
-
-