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 voidAdd a listener that gets called when we clear the full cachestatic voidClear the cache.static HashtablefindOrCreate(Object owner) Find the cache associated withownerand if not there, create a new cachestatic ObjectGet the cached object.static ObjectGet the cached object.static byte[]getCachedFile(String group, String id) Get the cached file under the group id if it existsstatic FilegetCachedFilePath(String group, String id) Get the cached file under the group id if it existsstatic FilegetCacheGroupDir(String group) What dir is the cache group instatic booleanGet whether we are caching or notstatic Fileget tmp dirstatic FilegetTmpFile(String prefix) get a tmp filestatic voidPrint the statistics for this cache.static voidPut an object in the cachestatic voidPut an object in the cachestatic voidputCachedFile(String group, String id, byte[] bytes) Write the cached filestatic voidRemove the cache associated with theowner.static voidRemove a particular item from the owner's cache.static voidsetCacheDir(File dir) set the cache dirstatic voidsetDoCache(boolean cache) Set whether we do caching.static voidsetMaxFileCacheSize(long maxSize) Set the max limit on the file cache sizestatic voidSet 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 withownerand 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().
-