ucar.unidata.util
Class CacheManager

java.lang.Object
  extended by 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 Summary
CacheManager()
          Default constructor; does nothing.
 
Method Summary
static void addCacheListener(ActionListener a)
          Add a listener that gets called when we clear the full cache
static void clearCache()
          Clear the cache.
static Hashtable findOrCreate(Object owner)
          Find the cache associated with owner and if not there, create a new cache
static Object get(Object owner, Object key)
          Get the cached object.
static Object get(Object owner, Object key, boolean force)
          Get the cached object.
static byte[] getCachedFile(String group, String id)
          Get the cached file under the group id if it exists
static File getCachedFilePath(String group, String id)
          Get the cached file under the group id if it exists
static File getCacheGroupDir(String group)
          What dir is the cache group in
static boolean getDoCache()
          Get whether we are caching or not
static File getTmpDir()
          get tmp dir
static File getTmpFile(String prefix)
          get a tmp file
static void printStats()
          Print the statistics for this cache.
static void put(Object owner, Object key, Object value)
          Put an object in the cache
static void put(Object owner, Object key, Object value, boolean force)
          Put an object in the cache
static void putCachedFile(String group, String id, byte[] bytes)
          Write the cached file
static void remove(Object owner)
          Remove the cache associated with the owner.
static void remove(Object owner, Object key)
          Remove a particular item from the owner's cache.
static void setCacheDir(File dir)
          set the cache dir
static void setDoCache(boolean cache)
          Set whether we do caching.
static void setMaxFileCacheSize(long maxSize)
          Set the max limit on the file cache size
static void setTmpDir(File dir)
          Set the tmp dir
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheManager

public CacheManager()
Default constructor; does nothing.

Method Detail

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().