Class CacheManager

java.lang.Object
ucar.unidata.util.CacheManager

public class CacheManager extends Object
A static class to manage a set of data caches. Each object could have a cache of data for specific data objects associated with it. This class is a central manager for all the caches. Effectively, it is a Hashtable of Hashtables. The key for the managed cache is the owner of the cached data. The value for the owner key is a Hashtable of cached Data objects.
Version:
$Revision: 1.15 $
Author:
IDV development team
  • Constructor Details

    • CacheManager

      public CacheManager()
      Default constructor; does nothing.
  • Method Details

    • setDoCache

      public static void setDoCache(boolean cache)
      Set whether we do caching. If we aren't doing caching then clear the cache.
      Parameters:
      cache - Do we do caching
    • getDoCache

      public static boolean getDoCache()
      Get whether we are caching or not
      Returns:
      true if caching
    • setCacheDir

      public static void setCacheDir(File dir)
      set the cache dir
      Parameters:
      dir - cache dir
    • setTmpDir

      public static void setTmpDir(File dir)
      Set the tmp dir
      Parameters:
      dir - tmp dir
    • getTmpDir

      public static File getTmpDir()
      get tmp dir
      Returns:
      the tmp dir
    • getTmpFile

      public static File getTmpFile(String prefix)
      get a tmp file
      Parameters:
      prefix - file prefix
      Returns:
      tmp file path
    • getCacheGroupDir

      public static File getCacheGroupDir(String group)
      What dir is the cache group in
      Parameters:
      group - cache group
      Returns:
      dir
    • getCachedFilePath

      public static File getCachedFilePath(String group, String id)
      Get the cached file under the group id if it exists
      Parameters:
      group - group
      id - id
      Returns:
      file bytes or null
    • getCachedFile

      public static byte[] getCachedFile(String group, String id)
      Get the cached file under the group id if it exists
      Parameters:
      group - group
      id - id
      Returns:
      file bytes or null
    • setMaxFileCacheSize

      public static void setMaxFileCacheSize(long maxSize)
      Set the max limit on the file cache size
      Parameters:
      maxSize - Max cache size
    • putCachedFile

      public static void putCachedFile(String group, String id, byte[] bytes)
      Write the cached file
      Parameters:
      group - group
      id - id
      bytes - bytes
    • put

      public static void put(Object owner, Object key, Object value)
      Put an object in the cache
      Parameters:
      owner - owner of the object
      key - key for the cached object
      value - value for key
    • put

      public static void put(Object owner, Object key, Object value, boolean force)
      Put an object in the cache
      Parameters:
      owner - owner of the object
      key - key for the cached object
      value - value for key
      force - true to cache even if doCache is false
    • clearCache

      public static void clearCache()
      Clear the cache.
    • addCacheListener

      public static void addCacheListener(ActionListener a)
      Add a listener that gets called when we clear the full cache
      Parameters:
      a - cache listener
    • findOrCreate

      public static Hashtable findOrCreate(Object owner)
      Find the cache associated with owner and if not there, create a new cache
      Parameters:
      owner - owner to search for
      Returns:
      caching table
    • get

      public static Object get(Object owner, Object key)
      Get the cached object.
      Parameters:
      owner - cache owner
      key - key within the cache
      Returns:
      the cached object
    • get

      public static Object get(Object owner, Object key, boolean force)
      Get the cached object.
      Parameters:
      owner - cache owner
      key - key within the cache
      force - true to force a lookup
      Returns:
      the cached object
    • remove

      public static void remove(Object owner)
      Remove the cache associated with the owner.
      Parameters:
      owner - owner of the cache
    • remove

      public static void remove(Object owner, Object key)
      Remove a particular item from the owner's cache.
      Parameters:
      owner - owner of the cache
      key - key for object to remove
    • printStats

      public static void printStats()
      Print the statistics for this cache. Glorified toString().