|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.zkoss.util.FastReadCache<K,V>
public class FastReadCache<K,V>
A CacheMap
that the possiblity to have cache hit is much more than
not. It maintains a reaonly cache (so no need to synchronize), and then
clone and replace it if there is a miss.
Thus, as time goes, most access can go directly to the readonly cache
without any synchronization or cloning.
Thread safe.
Field Summary |
---|
Fields inherited from interface org.zkoss.util.Cache |
---|
DEFAULT_LIFETIME, DEFAULT_MAX_SIZE |
Constructor Summary | |
---|---|
FastReadCache()
Constructor. |
|
FastReadCache(int maxSize,
int lifetime)
Constructor. |
Method Summary | |
---|---|
void |
clear()
Clears all objects being cached. |
boolean |
containsKey(java.lang.Object key)
Returns whether the specified key is stored. |
V |
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. |
V |
put(K key,
V value)
Stores an object to the cache. |
V |
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 FastReadCache()
public FastReadCache(int maxSize, int lifetime)
Method Detail |
---|
public boolean containsKey(java.lang.Object key)
Cache
containsKey
in interface Cache<K,V>
public V get(java.lang.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(java.lang.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)
Cache
Cache.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()
Cache
Cache.DEFAULT_MAX_SIZE
.
An mapping won't be removed by GC unless the minimal lifetime
or the maximal allowed size exceeds.
getMaxSize
in interface Cache<K,V>
Cache.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 |