Issue #23 fix the LRUCacheFS so it does not create a cache directory if

it is not using it, it creates different cache directories for different
users and it has better error checking.
Change-Id: I486a98583a0d952fe7753d28ae6a2026e943bfb4
Former-commit-id: 867fecfc6a [formerly 112679d14a] [formerly 867fecfc6a [formerly 112679d14a] [formerly 2d0ba75b3e [formerly a29e7c8028c4d3099627da4a5586b7c6d13b51fb]]]
Former-commit-id: 2d0ba75b3e
Former-commit-id: ebb6070fde [formerly e06cfaca02]
Former-commit-id: 2ce5929792
This commit is contained in:
Ben Steffensmeier 2012-01-26 15:13:40 -06:00
parent ac8f5b34b0
commit 52d6ca3366

View file

@ -117,6 +117,8 @@ public class LRUCacheFS {
else
FILESYSTEM_CACHE_SIZE = sz;
fsCache = new LRUCacheInternal(FILESYSTEM_CACHE_SIZE * 1024 * 1024);
String cache = null; // TODO allow configurable
/** Default to java temp directory */
@ -124,19 +126,24 @@ public class LRUCacheFS {
cache = System.getProperty("java.io.tmpdir");
}
/** Set the directory */
cacheDir = new File(cache, "vizCache");
if (cacheDir.exists() == false) {
cacheDir.mkdir();
String dirName = "vizCache";
String user = System.getProperty("user.name");
if (user != null) {
dirName = dirName + "." + user;
}
/** Set the directory */
cacheDir = new File(cache, dirName);
if (cacheDir.exists()) {
/** Register any files in the cache with the cache */
File[] files = cacheDir.listFiles();
fsCache = new LRUCacheInternal(FILESYSTEM_CACHE_SIZE * 1024 * 1024);
if (files != null) {
for (File file : files) {
poll(file);
}
}
}
}
private LRUCacheFS() {
@ -152,7 +159,7 @@ public class LRUCacheFS {
public static File createCacheFile() {
File file = null;
try {
file = File.createTempFile("cached", ".bin", cacheDir);
file = File.createTempFile("cached", ".bin", getCacheDirectory());
file.setReadable(true, false);
file.setWritable(true, false);
} catch (IOException e) {
@ -181,6 +188,9 @@ public class LRUCacheFS {
* @return the cache directory
*/
public static File getCacheDirectory() {
if (cacheDir.exists() == false) {
cacheDir.mkdir();
}
return cacheDir;
}