public class DiskCache2 extends Object
Each DiskCache has a "root directory", which may be set as an absolute path, or reletive to the DiskCache "home directory". The root directory must be writeable. The DiskCache home directory is set in the following order:
| Modifier and Type | Field and Description |
|---|---|
static int |
CACHEPATH_POLICY_NESTED_DIRECTORY |
static int |
CACHEPATH_POLICY_NESTED_TRUNCATE |
static int |
CACHEPATH_POLICY_ONE_DIRECTORY |
| Constructor and Description |
|---|
DiskCache2(String root,
boolean reletiveToHome,
int persistMinutes,
int scourEveryMinutes)
Create a cache on disk.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cleanCache(File dir,
StringBuilder sbuff,
boolean isRoot)
Remove any files or directories whose last modified time greater than persistMinutes
|
File |
createUniqueFile(String prefix,
String suffix)
Create a new, uniquely named file in the root directory.
|
void |
exit()
Be sure to call this when your application exits, otherwise the scour thread may not die.
|
File |
getCacheFile(String fileLocation)
Get a File in the cache, corresponding to the fileLocation.
|
String |
getRootDirectory()
Get the cache root directory.
|
static void |
main(String[] args)
debug
|
void |
setCachePathPolicy(int cachePathPolicy,
String cachePathPolicyParam)
Set the cache path policy
|
void |
setLogger(org.slf4j.Logger cacheLog)
Optionally set a logger.
|
void |
setPolicy(int cachePathPolicy)
Set the cache path policy
|
void |
setRootDirectory(String cacheDir) |
void |
showCache(PrintStream pw)
Show cache contents.
|
public static int CACHEPATH_POLICY_ONE_DIRECTORY
public static int CACHEPATH_POLICY_NESTED_DIRECTORY
public static int CACHEPATH_POLICY_NESTED_TRUNCATE
public DiskCache2(String root, boolean reletiveToHome, int persistMinutes, int scourEveryMinutes)
root - the root directory of the cache. Must be writeable.reletiveToHome - if the root directory is reletive to the cache home directory.persistMinutes - a file is deleted if its last modified time is greater than persistMinutesscourEveryMinutes - how often to run the scour process. If <= 0, dont scour.public void exit()
public void setLogger(org.slf4j.Logger cacheLog)
cacheLog - use this loggerpublic void setRootDirectory(String cacheDir)
public String getRootDirectory()
public File getCacheFile(String fileLocation)
fileLocation - logical file locationpublic File createUniqueFile(String prefix, String suffix)
prefix - The prefix string to be used in generating the file's
name; must be at least three characters longsuffix - The suffix string to be used in generating the file's
name; may be null, in which case the
suffix ".tmp" will be usedpublic void setCachePathPolicy(int cachePathPolicy,
String cachePathPolicyParam)
cachePathPolicy - one of:
CACHEPATH_POLICY_ONE_DIRECTORY (default) : replace "/" with "-", so all files are in one directory.
CACHEPATH_POLICY_NESTED_DIRECTORY: cache files are in nested directories under the root.
CACHEPATH_POLICY_NESTED_TRUNCATE: eliminate leading directoriescachePathPolicyParam - for CACHEPATH_POLICY_NESTED_TRUNCATE, eliminate this stringpublic void setPolicy(int cachePathPolicy)
cachePathPolicy - one of CACHEPATH_POLICY__XXXXpublic void showCache(PrintStream pw)
pw - write to this PrintStream.public void cleanCache(File dir, StringBuilder sbuff, boolean isRoot)
dir - clean starting heresbuff - status messages here, may be nullisRoot - delete empty directories, bit not root directorypublic static void main(String[] args) throws IOException
IOExceptionCopyright © 1999-2012 UCAR/Unidata. All Rights Reserved.