pom.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/yssh/run/InitDataRunner.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/yssh/utils/CacheUtils.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
pom.xml
@@ -191,11 +191,12 @@ <version>22.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>31.1-jre</version> </dependency> <!--Caffeine缂撳瓨--> <dependency> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>caffeine</artifactId> <version>2.9.3</version> </dependency> </dependencies> <profiles> src/main/java/com/yssh/run/InitDataRunner.java
@@ -1,6 +1,6 @@ package com.yssh.run; import com.yssh.utils.CacheUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -11,25 +11,26 @@ import com.yssh.service.ICommonService; import com.yssh.service.IDictRecordService; @Component public class InitDataRunner implements ApplicationRunner{ public class InitDataRunner implements ApplicationRunner { protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private ICommonService commonService; @Autowired private IDictRecordService dictRecordService; @Override public void run(ApplicationArguments args) throws Exception { boolean tableExists = commonService.checkTableExists("dict_record"); if (!tableExists) { dictRecordService.createDictRecoTable(); } //璇诲彇dat鏁版嵁 commonService.readDatData(); } protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private ICommonService commonService; @Autowired private IDictRecordService dictRecordService; @Override public void run(ApplicationArguments args) throws Exception { CacheUtils.init(); boolean tableExists = commonService.checkTableExists("dict_record"); if (!tableExists) { dictRecordService.createDictRecoTable(); } //璇诲彇dat鏁版嵁 commonService.readDatData(); } } src/main/java/com/yssh/utils/CacheUtils.java
对比新文件 @@ -0,0 +1,35 @@ package com.yssh.utils; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import org.checkerframework.checker.nullness.qual.NonNull; import java.util.concurrent.TimeUnit; public class CacheUtils { private static @NonNull Cache<String, Object> cache; public static void init() { cache = Caffeine.newBuilder() .initialCapacity(2) .maximumSize(1024) .expireAfterWrite(24, TimeUnit.HOURS) .build(); } public static Object get(String key) { return cache.getIfPresent(key); } public static void put(String key, Object obj) { cache.put(key, obj); } public static void remove(String key) { cache.invalidate(key); } public static void clear() { cache.invalidateAll(); } }