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: a29e7c8028c4d3099627da4a5586b7c6d13b51fb
This commit is contained in:
Ben Steffensmeier 2012-01-26 15:13:40 -06:00
parent e9744bb16a
commit 2d0ba75b3e

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,17 +126,22 @@ 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;
}
/** Register any files in the cache with the cache */
File[] files = cacheDir.listFiles();
fsCache = new LRUCacheInternal(FILESYSTEM_CACHE_SIZE * 1024 * 1024);
for (File file : files) {
poll(file);
/** Set the directory */
cacheDir = new File(cache, dirName);
if (cacheDir.exists()) {
/** Register any files in the cache with the cache */
File[] files = cacheDir.listFiles();
if (files != null) {
for (File file : files) {
poll(file);
}
}
}
}
@ -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;
}