beta,gamma的Guava缓存实体类增加init方法,读取nacos配置时间实现控制缓存时长
人工交互启动类增加方法生成beta,gamma的Gauva缓存实体初始化 增加DurationProperties实体类接收读取nacos配置缓存时间信息
This commit is contained in:
parent
01b6f4e9bf
commit
c65d5bc9ae
|
@ -0,0 +1,16 @@
|
|||
package org.jeecg.common.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "duration")
|
||||
public class DurationProperties implements Serializable {
|
||||
|
||||
private Integer cache;
|
||||
|
||||
}
|
|
@ -2,29 +2,36 @@ package org.jeecg.common.cache;
|
|||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import org.jeecg.common.properties.DurationProperties;
|
||||
import org.jeecg.modules.entity.vo.BetaDataFile;
|
||||
import org.jeecg.modules.entity.vo.PHDFile;
|
||||
import org.jeecg.modules.entity.vo.SeriseData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class BetaCache {
|
||||
private Cache<String, BetaDataFile> betaCache = CacheBuilder.newBuilder()
|
||||
|
||||
@Autowired
|
||||
private DurationProperties durationProperties;
|
||||
|
||||
private Cache<String, BetaDataFile> betaCache;
|
||||
|
||||
public void initCache() {
|
||||
betaCache = CacheBuilder.newBuilder()
|
||||
//设置缓存初始大小,应该合理设置,后续会扩容
|
||||
.initialCapacity(10)
|
||||
//最大值
|
||||
.maximumSize(100)
|
||||
//并发数设置
|
||||
.concurrencyLevel(5)
|
||||
//缓存过期时间,写入后5秒钟过期
|
||||
.expireAfterWrite(24, TimeUnit.HOURS)
|
||||
//缓存过期时间,写入后XX小时后过期
|
||||
.expireAfterWrite(durationProperties.getCache(), TimeUnit.HOURS)
|
||||
//统计缓存命中率
|
||||
.recordStats()
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
public Cache<String, BetaDataFile> getBetaCache() {
|
||||
return betaCache;
|
||||
|
|
|
@ -3,25 +3,36 @@ package org.jeecg.common.cache;
|
|||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import org.jeecg.modules.entity.vo.PHDFile;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class LocalCache {
|
||||
private Cache<String, PHDFile> phdCache = CacheBuilder.newBuilder()
|
||||
|
||||
@Value("${duration.cache}")
|
||||
private Long duration;
|
||||
|
||||
private Cache<String, PHDFile> phdCache;
|
||||
|
||||
public void initCache() {
|
||||
phdCache = CacheBuilder.newBuilder()
|
||||
//设置缓存初始大小,应该合理设置,后续会扩容
|
||||
.initialCapacity(10)
|
||||
//最大值
|
||||
.maximumSize(100)
|
||||
//并发数设置
|
||||
.concurrencyLevel(5)
|
||||
//缓存过期时间,写入后5秒钟过期
|
||||
.expireAfterWrite(24, TimeUnit.HOURS)
|
||||
//缓存过期时间,写入后XX小时后过期
|
||||
.expireAfterWrite(duration, TimeUnit.HOURS)
|
||||
//统计缓存命中率
|
||||
.recordStats()
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
public Cache<String, PHDFile> getPHDCache() {
|
||||
return phdCache;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package org.jeecg;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.cache.BetaCache;
|
||||
import org.jeecg.common.cache.LocalCache;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
@ -20,6 +23,12 @@ import java.net.UnknownHostException;
|
|||
@EnableFeignClients(basePackages = {"org.jeecg"})
|
||||
@EnableScheduling
|
||||
public class JeecgSpectrumAnalysisApplication extends SpringBootServletInitializer implements CommandLineRunner {
|
||||
@Autowired
|
||||
private LocalCache localCache;
|
||||
@Autowired
|
||||
private BetaCache betaCache;
|
||||
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(JeecgSpectrumAnalysisApplication.class);
|
||||
|
@ -44,5 +53,8 @@ public class JeecgSpectrumAnalysisApplication extends SpringBootServletInitializ
|
|||
//加载dll工具库
|
||||
System.loadLibrary("ReadPHDFile");
|
||||
System.loadLibrary("GammaAnaly");
|
||||
//创建缓存
|
||||
betaCache.initCache();
|
||||
localCache.initCache();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user