Commit 5fd27834 authored by wangwei's avatar wangwei

支持关闭缓存预热

parent 7acae66b
......@@ -38,7 +38,7 @@ allprojects {
}
group = "cn.com.duiba.boot"
version = "0.0.59"
version = "0.0.60-SNAPSHOT"
}
subprojects {
......
......@@ -57,7 +57,10 @@ public class CacheConfig implements InitializingBean {
@Value("${local.cache.warmup.enable:false}")
private Boolean cacheEnable;
public void onMainContextRefreshed(){
public void onMainContextRefreshed() {
if (!cacheEnable) {
return;
}
String[] names = applicationContext.getBeanDefinitionNames();
for (String beanName : names) {
try {
......@@ -118,15 +121,15 @@ public class CacheConfig implements InitializingBean {
field.setAccessible(false);
}
}
}catch(Exception e){
} catch (Exception e) {
logger.warn("cache实例获取异常", e);
}
}
}
// 顺序最靠后 等其他地方处理MainContextRefreshedEvent事件完成后
public void onServerCache(){
try{
public void onServerCache() {
try {
// 本地缓存预热开关 : 默认关闭
if (!cacheEnable) {
logger.warn("Cache preheating failed,because cacheEnable is false");
......@@ -138,7 +141,7 @@ public class CacheConfig implements InitializingBean {
return;
}
logger.info("container of all registered AppInfo size: {}", instances.size());
List<InstanceInfo> list = instances.stream().sorted((o1, o2) -> (int) (o2.getLeaseInfo().getServiceUpTimestamp()-o1.getLeaseInfo().getServiceUpTimestamp())).collect(Collectors.toList());
List<InstanceInfo> list = instances.stream().sorted((o1, o2) -> (int) (o2.getLeaseInfo().getServiceUpTimestamp() - o1.getLeaseInfo().getServiceUpTimestamp())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(list)) {
logger.warn("Cache preheating failed,because 服务启动获取【" + appName + "】列表信息为空");
return;
......@@ -217,7 +220,7 @@ public class CacheConfig implements InitializingBean {
}
});
} catch (Exception e) {
logger.warn("服务启动获取【" + appName +"】列表信息失败", e);
logger.warn("服务启动获取【" + appName + "】列表信息失败", e);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment