提交 60346aea authored 作者: yangli's avatar yangli

.

上级 280629f8
......@@ -11,6 +11,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author yangli
......@@ -22,13 +23,15 @@ public class InstalledProgramCache {
private static List<Map<String, String>> programList;
public List<Map<String, String>> getPrograms() throws IOException {
if (programList == null) loadProgramListJob();
return programList;
}
@Scheduled(fixedDelay = 5000)
@Scheduled(fixedDelay = 300000)
public void loadProgramListJob() throws IOException {
List<Map<String, String>> programs = new ArrayList<>();
String[] regPaths = {
......@@ -49,7 +52,10 @@ public class InstalledProgramCache {
programList = programs;
}
private static final Map<String, Map<String, String>> programInfoCache = new ConcurrentHashMap<>();
private Map<String, String> queryProgramInfo(String key) throws IOException {
if (programInfoCache.containsKey(key)) return programInfoCache.get(key);
Map<String, String> info = new HashMap<>();
Process process = Runtime.getRuntime().exec("cmd /c reg query " + key);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"))) {
......@@ -68,6 +74,13 @@ public class InstalledProgramCache {
}
process.destroy();
}
programInfoCache.put(key, info);
return info;
}
// 30分钟清除一次缓存
@Scheduled(fixedDelay = 1800000)
public void clearProgramInfoCache() {
programInfoCache.clear();
}
}
......@@ -216,6 +216,8 @@ public class ProgramController {
@GetMapping(value = "{type}/get_version")
public R<String> getVersion(@PathVariable @Pattern(regexp = "install|upgrade") String type,
@RequestParam @NotBlank String name) throws IOException {
// 查最新版本之前,手动清掉缓存,重新扫一遍
installedProgramCache.clearProgramInfoCache();
installedProgramCache.loadProgramListJob();
return type.equals("install") ?
installedProgramCache.getPrograms().stream()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论