Package org.zkoss.util.resource
Class ResourceCache<K,V>
Used to cache resources.
To use this class, you have to implement
Loader 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:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.zkoss.util.CacheMap
CacheMap.Value<V> -
Field Summary
FieldsFields inherited from class org.zkoss.util.CacheMap
EXPUNGE_CONTINUE, EXPUNGE_NO, EXPUNGE_STOP, EXPUNGE_YESFields inherited from interface org.zkoss.util.Cache
DEFAULT_LIFETIME, DEFAULT_MAX_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionResourceCache(Loader<K, V> loader) Constructor.ResourceCache(Loader<K, V> loader, int initsz) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()It is OK to clear up all cached resources if you don't want to cache it.Returns the resource, or null if not found.intReturns how often to check (unit=milliseconds).Returns the loader.Don't use it.It is OK to remove the resource if you don't want to cache it.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, valuesMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
_loader
The loader.
-
-
Constructor Details
-
ResourceCache
Constructor.- Parameters:
loader- the loader to load resource
-
ResourceCache
Constructor.- Parameters:
loader- the loader to load resourceinitsz- the initial size of the map
-
-
Method Details
-
getLoader
Returns the loader. -
getCheckPeriod
public int getCheckPeriod()Returns how often to check (unit=milliseconds).Default: 5000
-
setCheckPeriod
Sets how often to check (unit=milliseconds).- Returns:
- this object
-
get
Returns the resource, or null if not found. -
put
Don't use it. -
remove
It is OK to remove the resource if you don't want to cache it. It is thread safe. -
clear
public void clear()It is OK to clear up all cached resources if you don't want to cache it. It is thread safe.
-