public abstract class BiLevelCacheMap extends Object implements Map
remove()
is very expensive.
Access to L1 map is not sychronized, to L2 map is synchronized. New values are first stored in L2. Once there have been more that a specified mumber of misses on L1, L1 and L2 maps are merged and the new map assigned to L1 and L2 cleared.
IMPORTANT:entrySet(), keySet(), and values() return unmodifiable snapshot collections.
Modifier and Type | Field and Description |
---|---|
protected Map |
_cacheL1
To preinitialize
_cacheL1 with default values use an initialization block |
Constructor and Description |
---|
BiLevelCacheMap(int mergeThreshold) |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set |
entrySet() |
Object |
get(Object key) |
boolean |
isEmpty() |
Set |
keySet() |
protected abstract Object |
newInstance(Object key)
Subclasses must implement to have automatic creation of new instances
or alternatively can use
put |
Object |
put(Object key,
Object value)
If key is already in cacheL1, the new value will show with a delay,
since merge L2->L1 may not happen immediately.
|
void |
putAll(Map map) |
Object |
remove(Object key)
This operation is very expensive.
|
int |
size() |
Collection |
values() |
protected Map _cacheL1
_cacheL1
with default values use an initialization blockpublic boolean containsKey(Object key)
containsKey
in interface Map
public boolean containsValue(Object value)
containsValue
in interface Map
public Object put(Object key, Object value)
size().
public Object remove(Object key)
public Collection values()
protected abstract Object newInstance(Object key)
put to add new items to the cache.
Implementing this method is prefered to guarantee that there will be only
one instance per key ever created. Calling put() to add items in a multi-
threaded situation will require external synchronization to prevent two
instances for the same key, which defeats the purpose of this cache
(put() is useful when initialization is done during startup and items
are not added during execution or when (temporarily) having possibly two
or more instances of the same key is not of concern).
key
- lookup keyCopyright © 2020 The Apache Software Foundation. All rights reserved.