fix: assets file cache bugs

This commit is contained in:
CaiHQ 2022-10-25 17:48:07 +08:00
parent 926078e081
commit e93c07ed84
2 changed files with 20 additions and 3 deletions

View File

@ -30,6 +30,7 @@ public class DOIPOverHttpHandler {
private static final Logger LOGGER = LogManager.getLogger(DOIPOverHttpHandler.class);
Map<String, ZipFile> zipFilePool = new HashMap<>();
Map<String, Long> lastVisit = new HashMap<>();
Map<String, Long> lastModified = new HashMap<>();
public synchronized void pruneZipPool() {
Set<String> toPrune = new HashSet<>();
@ -45,6 +46,7 @@ public class DOIPOverHttpHandler {
ZipFile zf = zipFilePool.get(str);
zipFilePool.remove(str);
lastVisit.remove(str);
lastModified.remove(str);
zf.close();
} catch (Exception e) {
@ -162,7 +164,6 @@ public class DOIPOverHttpHandler {
}
private void sendAssets(JsonObject arg, ChannelHandlerContext ctx) throws Exception {
ContractMeta meta =
CMActions.manager.statusRecorder.getContractMeta(
arg.get("contractID").getAsString());
@ -199,10 +200,22 @@ public class DOIPOverHttpHandler {
try {
ZipFile cachedFile = zipFilePool.get(scriptStr);
if (cachedFile == null) {
File f = new File(scriptStr);
cachedFile =
new ZipFile(new File(scriptStr));
new ZipFile(f);
zipFilePool.put(scriptStr, cachedFile);
lastModified.put(scriptStr, f.lastModified());
} else {
File f = new File(scriptStr);
if (lastModified.get(scriptStr) != f.lastModified()) {
cachedFile.close();
cachedFile =
new ZipFile(f);
zipFilePool.put(scriptStr, cachedFile);
lastModified.put(scriptStr, f.lastModified());
}
}
lastVisit.put(scriptStr, System.currentTimeMillis());
return cachedFile;
} catch (Exception e) {

View File

@ -681,7 +681,11 @@ public class NodeCenterClientController implements NodeCenterConn {
@Action(async = true)
public void onDistributeYPK(JsonObject json, ResultCallback rc) {
onDistribute(json, rc);
try {
onDistribute(json, rc);
} catch (IOException e) {
e.printStackTrace();
}
}
@Action(async = true)