Package org.jgroups.blocks
Class LazyRemovalCache<K,V>
java.lang.Object
org.jgroups.blocks.LazyRemovalCache<K,V>
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentMap<K, LazyRemovalCache.Entry<V>> private final longprivate final intMax number of elements, if exceeded, we remove all elements marked as removable and older than max_age ms -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanprotected booleanvoidprotected voidvoidaddAllIfAbsent(Map<K, V> m) booleanaddIfAbsent(K key, V val) private voidvoidclear(boolean force) booleancontainsKey(K key) booleancontainsKeys(Collection<K> keys) Returns true if all of the keys in keys are present.contents()contents(boolean skip_removed_values) entrySet()getByValue(V val) Returns a (non-removable) entry based on the valuekeySet()Adds all value which have not been marked as removable to the returned setprintCache(LazyRemovalCache.Printable print_function) voidvoidvoidremoveAll(Collection<K> keys) voidremoveAll(Collection<K> keys, boolean force) voidRemoves elements marked as removablevoidremoveMarkedElements(boolean force) Removes elements marked as removablevoidretainAll(Collection<K> keys) voidretainAll(Collection<K> keys, boolean force) intsize()toString()values()
-
Field Details
-
map
-
max_elements
private final int max_elementsMax 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 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 Details
-
add
-
addIfAbsent
-
addAll
-
addAllIfAbsent
-
entrySet
-
containsKey
-
containsKeys
Returns true if all of the keys in keys are present. Returns false if one or more of the keys are absent -
get
-
getByValue
Returns a (non-removable) entry based on the value -
remove
-
remove
-
removeAll
-
removeAll
-
clear
public void clear(boolean force) -
retainAll
-
retainAll
-
keySet
-
values
-
valuesIterator
-
nonRemovedValues
Adds all value which have not been marked as removable to the returned set- Returns:
-
contents
-
contents
-
size
public int size() -
printCache
-
printCache
-
toString
-
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
-
addAll
-