|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.myfaces.util.BiLevelCacheMap
A bi-level cache based on HashMap for caching objects with minimal sychronization
overhead. The limitation is that 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.
Field Summary | |
protected java.util.Map |
_cacheL1
To preinitialize _cacheL1 with default values use an initialization block |
Constructor Summary | |
BiLevelCacheMap(int mergeThreshold)
|
Method Summary | |
void |
clear()
|
boolean |
containsKey(java.lang.Object key)
|
boolean |
containsValue(java.lang.Object value)
|
java.util.Set |
entrySet()
|
java.lang.Object |
get(java.lang.Object key)
|
boolean |
isEmpty()
|
java.util.Set |
keySet()
|
protected abstract java.lang.Object |
newInstance(java.lang.Object key)
Subclasses must implement to have automatic creation of new instances or alternatively can use put |
java.lang.Object |
put(java.lang.Object key,
java.lang.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(java.util.Map map)
|
java.lang.Object |
remove(java.lang.Object key)
This operation is very expensive. |
int |
size()
|
java.util.Collection |
values()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Map |
equals, hashCode |
Field Detail |
protected java.util.Map _cacheL1
_cacheL1
with default values use an initialization block
Constructor Detail |
public BiLevelCacheMap(int mergeThreshold)
Method Detail |
public boolean isEmpty()
isEmpty
in interface java.util.Map
public void clear()
clear
in interface java.util.Map
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
public java.util.Set entrySet()
entrySet
in interface java.util.Map
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
public java.util.Set keySet()
keySet
in interface java.util.Map
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
size().
- Specified by:
put
in interface java.util.Map
public void putAll(java.util.Map map)
putAll
in interface java.util.Map
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
public int size()
size
in interface java.util.Map
public java.util.Collection values()
values
in interface java.util.Map
protected abstract java.lang.Object newInstance(java.lang.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).
- Parameters:
key
- lookup key
- Returns:
- new instace for the requested key
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |