org.zkoss.util.resource
Class ResourceCache

java.lang.Object
  extended by org.zkoss.util.CacheMap
      extended by org.zkoss.util.resource.ResourceCache
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map, Cache

public class ResourceCache
extends CacheMap

Used to cache resouces. 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 libary propety 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
 
Field Summary
protected  Loader _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
ResourceCache(Loader loader)
          Constructor.
ResourceCache(Loader loader, int initsz)
          Constructor.
 
Method Summary
 void clear()
          It is OK to clear up all cached resources if you don't want to cache it.
 java.lang.Object get(java.lang.Object src)
          Returns the resource, or null if not found.
 int getCheckPeriod()
          Returns how often to check (unit=milliseconds).
 Loader 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, containsValue, entrySet, equals, expunge, getLifetime, getMaxSize, getWithoutExpunge, hashCode, isEmpty, isEmptyWithoutExpunge, keySet, newQueue, onExpunge, putAll, setLifetime, setMaxSize, shallExpunge, size, sizeWithoutExpunge, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_loader

protected final Loader _loader
The loader.

Constructor Detail

ResourceCache

public ResourceCache(Loader loader)
Constructor.

Parameters:
loader - the loader to load resource

ResourceCache

public ResourceCache(Loader loader,
                     int initsz)
Constructor.

Parameters:
loader - the loader to load resource
initsz - the initial size of the map
Method Detail

getLoader

public Loader getLoader()
Returns the loader.


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 java.lang.Object get(java.lang.Object src)
Returns the resource, or null if not found.

Specified by:
get in interface java.util.Map
Specified by:
get in interface Cache
Overrides:
get in class CacheMap

put

public java.lang.Object put(java.lang.Object src,
                            java.lang.Object val)
Don't use it.

Specified by:
put in interface java.util.Map
Specified by:
put in interface Cache
Overrides:
put in class CacheMap
Returns:
the previous value of the same, or null if no such value

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.

Specified by:
remove in interface java.util.Map
Specified by:
remove in interface Cache
Overrides:
remove in class CacheMap
Returns:
the object if found.

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.

Specified by:
clear in interface java.util.Map
Specified by:
clear in interface Cache
Overrides:
clear in class CacheMap


Copyright © 2005-2009 Potix Corporation. All Rights Reserved. SourceForge.net Logo