|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.zkoss.util.ThreadLocalCache<K,V>
public class ThreadLocalCache<K,V>
A cache that resides on the thread local memory. The performance is excellent since no need to synchronize the access. However, it takes more memory since each thread has its own map. In addition, it might cause hot re-deployment failed to free old classes if the map stores the references of the classes loaded by the Web Application class loader.
| Field Summary |
|---|
| Fields inherited from interface org.zkoss.util.Cache |
|---|
DEFAULT_LIFETIME, DEFAULT_MAX_SIZE |
| Constructor Summary | |
|---|---|
ThreadLocalCache()
Constructs a thread-local cache with the default setting: max size=128 and lifetime=30minutes. |
|
ThreadLocalCache(int maxSize,
int lifetime)
Constucts a thread-local cache with the specified max size and the lifetime. |
|
| Method Summary | |
|---|---|
void |
clear()
Clears all objects being cached. |
boolean |
containsKey(Object key)
Returns whether the specified key is stored. |
void |
copyTo(Map<K,V> map)
Deprecated. As of release 6.0.0, use Map.putAll(java.util.Map extends K, ? extends V>) instead. |
V |
get(Object key)
Returns the object of the specified key, or null if not found. |
int |
getLifetime()
Returns the minimal lifetime, unit=milliseconds. |
int |
getMaxSize()
Returns the maximal allowed size. |
boolean |
isEmpty()
Returns whether the cache for the current thread is empty. |
V |
put(K key,
V value)
Stores an object to the cache. |
V |
remove(Object key)
Removes an object from the cache. |
void |
setLifetime(int lifetime)
Sets the minimal lifetime. |
void |
setMaxSize(int maxsize)
Sets the maximal allowed size. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ThreadLocalCache(int maxSize,
int lifetime)
public ThreadLocalCache()
| Method Detail |
|---|
public boolean isEmpty()
public void copyTo(Map<K,V> map)
Map.putAll(java.util.Map extends K, ? extends V>) instead.
public boolean containsKey(Object key)
Cache
containsKey in interface Cache<K,V>public V get(Object key)
Cache
get in interface Cache<K,V>
public V put(K key,
V value)
Cache
put in interface Cache<K,V>public V remove(Object key)
Cache
remove in interface Cache<K,V>public void clear()
Cache
clear in interface Cache<K,V>public int getLifetime()
Cache
getLifetime in interface Cache<K,V>Cache.getMaxSize()public void setLifetime(int lifetime)
CacheCache.DEFAULT_LIFETIME.
setLifetime in interface Cache<K,V>lifetime - the lifetime, unit=milliseconds;
if non-posive, they will be removed immediately.Cache.getLifetime()public int getMaxSize()
Defalut: 128 (it is smaller than most cache since this cache one per thread). An mapping won't be removed by GC unless the minimal lifetime or the maximal allowed size exceeds.
getMaxSize in interface Cache<K,V>getLifetime()public void setMaxSize(int maxsize)
Cache
setMaxSize in interface Cache<K,V>Cache.getMaxSize()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||