forked from integrated_whb/integrated_whb
共通信息
parent
cf3c099a38
commit
c7cfb27443
|
@ -22,30 +22,6 @@ import java.util.logging.Logger;
|
|||
@Component
|
||||
public class CaffeineUtil {
|
||||
private static final Logger logger = Logger.getLogger(CaffeineUtil.class.getName());
|
||||
@Resource
|
||||
private DictionariesMapper dictionariesMapper;
|
||||
|
||||
@Bean(name = "caffeineCache")
|
||||
public Cache<String, Object> caffeineCache() {
|
||||
Cache<String, Object> build = Caffeine.newBuilder()
|
||||
//8小时没有读写自动删除
|
||||
.expireAfterAccess(8, TimeUnit.HOURS)
|
||||
// 当垃圾收集器需要释放内存时驱逐
|
||||
.softValues()
|
||||
//最大容量1个,超过会自动清理空间
|
||||
.maximumSize(1)
|
||||
.removalListener(((key, value, cause) -> {
|
||||
//清理通知 key,value ==> 键值对 cause ==> 清理原因
|
||||
System.out.printf("Key %s was removed (%s)%n", key, cause);
|
||||
})).build();
|
||||
// 加载一次
|
||||
build.get("xzqh", x -> {
|
||||
List<PageData> all = dictionariesMapper.getAll();
|
||||
Map fileSort = AdministrativeUntil.getFileSort(all);
|
||||
return fileSort;
|
||||
});
|
||||
return build;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 登录token
|
||||
|
@ -67,22 +43,4 @@ public class CaffeineUtil {
|
|||
})).build();
|
||||
return loginToken;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 行政区划
|
||||
* @Author: dearLin
|
||||
* @Date: 2023/6/12/012 9:25
|
||||
* @Param: [com.github.benmanes.caffeine.cache.Cache<java.lang.String, java.lang.Object>] [build]
|
||||
* @Return: void
|
||||
*/
|
||||
@Async
|
||||
public void loadOnce(Cache<String, Object> build) {
|
||||
// 加载一次
|
||||
build.get("xzqh", x -> {
|
||||
List<PageData> all = dictionariesMapper.getAll();
|
||||
Map fileSort = AdministrativeUntil.getFileSort(all);
|
||||
return fileSort;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue