Class ResourceCache<K,V>

java.lang.Object
org.zkoss.util.CacheMap<Object,Object>
org.zkoss.util.resource.ResourceCache<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>, Cache<Object,Object>

public class ResourceCache<K,V> extends CacheMap<Object,Object>
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:
  • Field Details

    • _loader

      protected final Loader<K,V> _loader
      The loader.
  • Constructor Details

    • ResourceCache

      public ResourceCache(Loader<K,V> loader)
      Constructor.
      Parameters:
      loader - the loader to load resource
    • ResourceCache

      public ResourceCache(Loader<K,V> loader, int initsz)
      Constructor.
      Parameters:
      loader - the loader to load resource
      initsz - the initial size of the map
  • Method Details

    • getLoader

      public Loader<K,V> 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 V get(Object src)
      Returns the resource, or null if not found.
      Specified by:
      get in interface Cache<K,V>
      Specified by:
      get in interface Map<K,V>
      Overrides:
      get in class CacheMap<Object,Object>
    • put

      public Object put(Object src, Object val)
      Don't use it.
      Specified by:
      put in interface Cache<K,V>
      Specified by:
      put in interface Map<K,V>
      Overrides:
      put in class CacheMap<Object,Object>
      Returns:
      the previous value of the same, or null if no such value
      Throws:
      UnsupportedOperationException - if called
    • remove

      public Object remove(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 Cache<K,V>
      Specified by:
      remove in interface Map<K,V>
      Overrides:
      remove in class CacheMap<Object,Object>
      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 Cache<K,V>
      Specified by:
      clear in interface Map<K,V>
      Overrides:
      clear in class CacheMap<Object,Object>