Package ucar.unidata.util
Class CacheManager
java.lang.Object
ucar.unidata.util.CacheManager
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Add a listener that gets called when we clear the full cachestatic void
Clear the cache.static Hashtable
findOrCreate
(Object owner) Find the cache associated withowner
and if not there, create a new cachestatic Object
Get the cached object.static Object
Get the cached object.static byte[]
getCachedFile
(String group, String id) Get the cached file under the group id if it existsstatic File
getCachedFilePath
(String group, String id) Get the cached file under the group id if it existsstatic File
getCacheGroupDir
(String group) What dir is the cache group instatic boolean
Get whether we are caching or notstatic File
get tmp dirstatic File
getTmpFile
(String prefix) get a tmp filestatic void
Print the statistics for this cache.static void
Put an object in the cachestatic void
Put an object in the cachestatic void
putCachedFile
(String group, String id, byte[] bytes) Write the cached filestatic void
Remove the cache associated with theowner
.static void
Remove a particular item from the owner's cache.static void
setCacheDir
(File dir) set the cache dirstatic void
setDoCache
(boolean cache) Set whether we do caching.static void
setMaxFileCacheSize
(long maxSize) Set the max limit on the file cache sizestatic void
Set the tmp dir
-
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
set the cache dir- Parameters:
dir
- cache dir
-
setTmpDir
Set the tmp dir- Parameters:
dir
- tmp dir
-
getTmpDir
get tmp dir- Returns:
- the tmp dir
-
getTmpFile
get a tmp file- Parameters:
prefix
- file prefix- Returns:
- tmp file path
-
getCacheGroupDir
What dir is the cache group in- Parameters:
group
- cache group- Returns:
- dir
-
getCachedFilePath
Get the cached file under the group id if it exists- Parameters:
group
- groupid
- id- Returns:
- file bytes or null
-
getCachedFile
Get the cached file under the group id if it exists- Parameters:
group
- groupid
- 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
Write the cached file- Parameters:
group
- groupid
- idbytes
- bytes
-
put
Put an object in the cache- Parameters:
owner
- owner of the objectkey
- key for the cached objectvalue
- value for key
-
put
Put an object in the cache- Parameters:
owner
- owner of the objectkey
- key for the cached objectvalue
- value for keyforce
- true to cache even if doCache is false
-
clearCache
public static void clearCache()Clear the cache. -
addCacheListener
Add a listener that gets called when we clear the full cache- Parameters:
a
- cache listener
-
findOrCreate
Find the cache associated withowner
and if not there, create a new cache- Parameters:
owner
- owner to search for- Returns:
- caching table
-
get
Get the cached object.- Parameters:
owner
- cache ownerkey
- key within the cache- Returns:
- the cached object
-
get
Get the cached object.- Parameters:
owner
- cache ownerkey
- key within the cacheforce
- true to force a lookup- Returns:
- the cached object
-
remove
Remove the cache associated with theowner
.- Parameters:
owner
- owner of the cache
-
remove
Remove a particular item from the owner's cache.- Parameters:
owner
- owner of the cachekey
- key for object to remove
-
printStats
public static void printStats()Print the statistics for this cache. Glorified toString().
-