Browse Source

增加缓存,优化性能

main
zhouxin5253@163.com 4 years ago
parent
commit
9cd0c8b3f0
  1. 6
      src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java

6
src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java

@ -15,7 +15,6 @@ import org.slf4j.LoggerFactory; @@ -15,7 +15,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
@ -29,6 +28,7 @@ public class TeambitionClientService { @@ -29,6 +28,7 @@ public class TeambitionClientService {
private static int chunkSize = 10485760; // 10MB
private TFile rootTFile = null;
private Map<String, TFile> nodeIdMap = new ConcurrentHashMap<>();
private Map<String, Set<TFile>> tFilesCache = new ConcurrentHashMap<>();
private final TeambitionClient client;
@ -38,6 +38,7 @@ public class TeambitionClientService { @@ -38,6 +38,7 @@ public class TeambitionClientService {
}
public Set<TFile> getTFiles(String nodeId) {
return tFilesCache.computeIfAbsent(nodeId, key -> {
NodeQuery nodeQuery = new NodeQuery();
nodeQuery.setOrgId(client.getOrgId());
nodeQuery.setOffset(0);
@ -60,6 +61,8 @@ public class TeambitionClientService { @@ -60,6 +61,8 @@ public class TeambitionClientService {
}
// 对文件名进行去重,只保留最新的一个
return tFileSets;
});
}
@ -310,5 +313,6 @@ public class TeambitionClientService { @@ -310,5 +313,6 @@ public class TeambitionClientService {
private void clearCache(String path) {
nodeIdMap.remove(path);
tFilesCache.clear();
}
}

Loading…
Cancel
Save