|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.zkoss.util.ThreadLocalCache
public class ThreadLocalCache
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(java.lang.Object key)
Returns whether the specified key is stored. |
void |
copyTo(java.util.Map map)
Puts all object cached in the current thread to the specifed map. |
java.lang.Object |
get(java.lang.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. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Stores an object to the cache. |
java.lang.Object |
remove(java.lang.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(java.util.Map map)
public boolean containsKey(java.lang.Object key)
Cache
containsKey
in interface Cache
public java.lang.Object get(java.lang.Object key)
Cache
get
in interface Cache
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
Cache
put
in interface Cache
public java.lang.Object remove(java.lang.Object key)
Cache
remove
in interface Cache
public void clear()
Cache
clear
in interface Cache
public int getLifetime()
Cache
getLifetime
in interface Cache
Cache.getMaxSize()
public void setLifetime(int lifetime)
Cache
Cache.DEFAULT_LIFETIME
.
setLifetime
in interface Cache
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
getLifetime()
public void setMaxSize(int maxsize)
Cache
setMaxSize
in interface Cache
Cache.getMaxSize()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |