@ThreadSafe
public class FileCache
extends java.lang.Object
NetcdfDataset.initNetcdfFileCache(...); // on application startup
...
NetcdfFile ncfile = null;
try {
ncfile = NetcdfDataset.acquireFile(location, cancelTask);
...
} finally {
if (ncfile != null) ncfile.close();
}
...
NetcdfDataset.shutdown(); // when terminating the application
All methods are thread safe.
Cleanup is done automatically in a background thread, using LRU algorithm.| Constructor and Description |
|---|
FileCache(int minElementsInMemory,
int maxElementsInMemory,
int period)
Constructor.
|
FileCache(int minElementsInMemory,
int softLimit,
int hardLimit,
int period)
Constructor.
|
FileCache(java.lang.String name,
int minElementsInMemory,
int softLimit,
int hardLimit,
int period)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
FileCacheable |
acquire(FileFactory factory,
java.lang.Object hashKey,
java.lang.String location,
int buffer_size,
CancelTask cancelTask,
java.lang.Object spiObject)
Acquire a FileCacheable from the cache, and lock it so no one else can use it.
|
FileCacheable |
acquire(FileFactory factory,
java.lang.String location,
CancelTask cancelTask)
Acquire a FileCacheable, and lock it so no one else can use it.
|
void |
clearCache(boolean force)
Remove all cache entries.
|
void |
disable()
Disable the cache, and force release all files.
|
void |
enable()
Enable the cache, with the current set of parameters.
|
java.lang.String |
getInfo(FileCacheable ncfile) |
void |
release(FileCacheable ncfile)
Release the file.
|
java.util.List<java.lang.String> |
showCache() |
void |
showCache(java.util.Formatter format)
Show individual cache entries, add to formatter.
|
void |
showStats(java.util.Formatter format)
Add stat report (hits, misses, etc) to formatter.
|
static void |
shutdown()
You must call shutdown() to shut down the background threads in order to get a clean process shutdown.
|
public FileCache(int minElementsInMemory,
int maxElementsInMemory,
int period)
minElementsInMemory - keep this number in the cachemaxElementsInMemory - trigger a cleanup if it goes over this number.period - (secs) do periodic cleanups every this number of seconds.public FileCache(int minElementsInMemory,
int softLimit,
int hardLimit,
int period)
minElementsInMemory - keep this number in the cachesoftLimit - trigger a cleanup if it goes over this number.hardLimit - if > 0, never allow more than this many elements. This causes a cleanup to be done in the calling thread.period - if > 0, do periodic cleanups every this number of seconds.public FileCache(java.lang.String name,
int minElementsInMemory,
int softLimit,
int hardLimit,
int period)
name - of file cacheminElementsInMemory - keep this number in the cachesoftLimit - trigger a cleanup if it goes over this number.hardLimit - if > 0, never allow more than this many elements. This causes a cleanup to be done in the calling thread.period - if > 0, do periodic cleanups every this number of seconds.public static void shutdown()
public void disable()
public void enable()
public FileCacheable acquire(FileFactory factory, java.lang.String location, CancelTask cancelTask) throws java.io.IOException
factory - use this factory to open the file; may not be nulllocation - file location, also used as the cache name, will be passed to the NetcdfFileFactorycancelTask - user can cancel, ok to be null.java.io.IOException - on errorpublic FileCacheable acquire(FileFactory factory, java.lang.Object hashKey, java.lang.String location, int buffer_size, CancelTask cancelTask, java.lang.Object spiObject) throws java.io.IOException
factory - use this factory to open the file if not in the cache; may not be nullhashKey - unique key for this file. If null, the location will be usedlocation - file location, may also used as the cache name, will be passed to the NetcdfFileFactorybuffer_size - RandomAccessFile buffer size, if <= 0, use default sizecancelTask - user can cancel, ok to be null.spiObject - sent to iosp.setSpecial() if not nulljava.io.IOException - on errorpublic void release(FileCacheable ncfile) throws java.io.IOException
ncfile - release this file.java.io.IOException - if file not in cache.public java.lang.String getInfo(FileCacheable ncfile) throws java.io.IOException
java.io.IOExceptionpublic void clearCache(boolean force)
force - if true, remove them even if they are currently locked.public void showCache(java.util.Formatter format)
format - add to thispublic java.util.List<java.lang.String> showCache()
public void showStats(java.util.Formatter format)
format - add to this