This commit is contained in:
Reinhard Pointner 2014-01-13 11:06:41 +00:00
parent db9dbeb0f4
commit c75b376140
1 changed files with 9 additions and 1 deletions

View File

@ -461,9 +461,12 @@ public class Main {
} }
final File lockFile = new File(cache, ".lock"); final File lockFile = new File(cache, ".lock");
boolean isNewCache = !lockFile.exists();
final RandomAccessFile handle = new RandomAccessFile(lockFile, "rw"); final RandomAccessFile handle = new RandomAccessFile(lockFile, "rw");
final FileChannel channel = handle.getChannel(); final FileChannel channel = handle.getChannel();
final FileLock lock = channel.tryLock(); final FileLock lock = channel.tryLock();
if (lock != null) { if (lock != null) {
// setup cache dir for ehcache // setup cache dir for ehcache
System.setProperty("ehcache.disk.store.dir", cache.getAbsolutePath()); System.setProperty("ehcache.disk.store.dir", cache.getAbsolutePath());
@ -476,16 +479,21 @@ public class Main {
// ignore // ignore
} }
if (cacheRevision != applicationRevision && applicationRevision > 0) { if (cacheRevision != applicationRevision && applicationRevision > 0 && !isNewCache) {
Logger.getLogger(Main.class.getName()).log(Level.WARNING, String.format("App version (r%d) does not match cache version (r%d): reset cache", applicationRevision, cacheRevision)); Logger.getLogger(Main.class.getName()).log(Level.WARNING, String.format("App version (r%d) does not match cache version (r%d): reset cache", applicationRevision, cacheRevision));
// tag cache with new revision number
isNewCache = true;
// delete all files related to previous cache instances // delete all files related to previous cache instances
for (File it : cache.listFiles()) { for (File it : cache.listFiles()) {
if (!it.equals(lockFile)) { if (!it.equals(lockFile)) {
delete(cache); delete(cache);
} }
} }
}
if (isNewCache) {
// set new cache revision // set new cache revision
channel.position(0); channel.position(0);
channel.write(Charset.forName("UTF-8").encode(String.valueOf(applicationRevision))); channel.write(Charset.forName("UTF-8").encode(String.valueOf(applicationRevision)));