共通信息

dev
zhangyanli 2024-03-13 08:41:46 +08:00
parent cf3c099a38
commit c7cfb27443
1 changed files with 0 additions and 42 deletions

View File

@ -22,30 +22,6 @@ import java.util.logging.Logger;
@Component @Component
public class CaffeineUtil { public class CaffeineUtil {
private static final Logger logger = Logger.getLogger(CaffeineUtil.class.getName()); 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 * @Description: token
@ -67,22 +43,4 @@ public class CaffeineUtil {
})).build(); })).build();
return loginToken; 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;
});
}
} }