Package org.zkoss.util.resource
Class ResourceCache<K,V>
- java.lang.Object
-
- org.zkoss.util.CacheMap<java.lang.Object,java.lang.Object>
-
- org.zkoss.util.resource.ResourceCache<K,V>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<java.lang.Object,java.lang.Object>
,Cache<java.lang.Object,java.lang.Object>
- Direct Known Subclasses:
ResourceCache
public class ResourceCache<K,V> extends CacheMap<java.lang.Object,java.lang.Object>
Used to cache resources. To use this class, you have to implementLoader
and then ResourceCache will use it to check whether a resource is gone, modified and load the resource.Unlike
CacheMap
, it is thread-safe.The default check period depends on the library property called org.zkoss.util.resource.checkPeriod (unit: second). If not specified, 5 seconds are assumed
- Author:
- tomyeh
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.zkoss.util.CacheMap
CacheMap.Value<V>
-
-
Field Summary
Fields Modifier and Type Field Description protected Loader<K,V>
_loader
The loader.-
Fields inherited from class org.zkoss.util.CacheMap
EXPUNGE_CONTINUE, EXPUNGE_NO, EXPUNGE_STOP, EXPUNGE_YES
-
Fields inherited from interface org.zkoss.util.Cache
DEFAULT_LIFETIME, DEFAULT_MAX_SIZE
-
-
Constructor Summary
Constructors Constructor Description ResourceCache(Loader<K,V> loader)
Constructor.ResourceCache(Loader<K,V> loader, int initsz)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
It is OK to clear up all cached resources if you don't want to cache it.V
get(java.lang.Object src)
Returns the resource, or null if not found.int
getCheckPeriod()
Returns how often to check (unit=milliseconds).Loader<K,V>
getLoader()
Returns the loader.java.lang.Object
put(java.lang.Object src, java.lang.Object val)
Don't use it.java.lang.Object
remove(java.lang.Object src)
It is OK to remove the resource if you don't want to cache it.ResourceCache
setCheckPeriod(int checkPeriod)
Sets how often to check (unit=milliseconds).-
Methods inherited from class org.zkoss.util.CacheMap
canExpunge, clone, containsKey, containsKeyWithoutExpunge, containsValue, entrySet, equals, expunge, getLifetime, getMaxSize, getWithoutExpunge, hashCode, isEmpty, isEmptyWithoutExpunge, keySet, onExpunge, putAll, setLifetime, setMaxSize, shallExpunge, size, sizeWithoutExpunge, toString, values
-
-
-
-
Method Detail
-
getCheckPeriod
public int getCheckPeriod()
Returns how often to check (unit=milliseconds).Default: 5000
-
setCheckPeriod
public ResourceCache setCheckPeriod(int checkPeriod)
Sets how often to check (unit=milliseconds).- Returns:
- this object
-
get
public V get(java.lang.Object src)
Returns the resource, or null if not found.
-
put
public java.lang.Object put(java.lang.Object src, java.lang.Object val)
Don't use it.
-
remove
public java.lang.Object remove(java.lang.Object src)
It is OK to remove the resource if you don't want to cache it. It is thread safe.
-
-