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
[formerly112679d14a
] [formerly867fecfc6a
[formerly112679d14a
] [formerly2d0ba75b3e
[formerly a29e7c8028c4d3099627da4a5586b7c6d13b51fb]]] Former-commit-id:2d0ba75b3e
Former-commit-id:ebb6070fde
[formerlye06cfaca02
] Former-commit-id:2ce5929792
This commit is contained in:
parent
ac8f5b34b0
commit
52d6ca3366
1 changed files with 20 additions and 10 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue