修改asn缓存初始化方法加入参数是否强制刷新,部署多个tomcat服务时个个tomcat缓存可能存在不一致的情况,这就需要强制重新加载缓存
This commit is contained in:
@@ -65,29 +65,17 @@ public class AsnCacheUtils{
|
||||
return configGroupInfos;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* 初始化缓存
|
||||
*
|
||||
* @param force是否强制刷新
|
||||
*/
|
||||
//@PostConstruct
|
||||
public synchronized static void init() {
|
||||
public synchronized static void init(boolean force) {
|
||||
long start=System.currentTimeMillis();
|
||||
logger.warn("AsnCacheUtils init start...");
|
||||
Cache cache=getCache(ASN_NO_CACHE);
|
||||
//查询总量
|
||||
Long count=configGroupInfoDao.getCountByType(4);
|
||||
//缓存key
|
||||
boolean loadDatabase=false;
|
||||
if(cache.getKeys().size()==0) {
|
||||
loadDatabase=true;
|
||||
}else {
|
||||
long c=0l;
|
||||
for(Object key:cache.getKeys()) {
|
||||
c+=getMap(key).size();
|
||||
}
|
||||
if(c!=count) {
|
||||
loadDatabase=true;
|
||||
}
|
||||
}
|
||||
if(loadDatabase) {
|
||||
if(force) {
|
||||
List<ConfigGroupInfo> list=configGroupInfoDao.findAllList(4);
|
||||
Map<Long,Map<Long,ConfigGroupInfo>> groupMap=Maps.newHashMap();
|
||||
for(ConfigGroupInfo configGroupInfo:list) {
|
||||
@@ -104,7 +92,41 @@ public class AsnCacheUtils{
|
||||
Element element = new Element(e.getKey(), e.getValue());
|
||||
cache.put(element);
|
||||
}
|
||||
}else {
|
||||
//查询总量
|
||||
Long count=configGroupInfoDao.getCountByType(4);
|
||||
boolean loadDatabase=false;
|
||||
if(cache.getKeys().size()==0) {
|
||||
loadDatabase=true;
|
||||
}else {
|
||||
long c=0l;
|
||||
for(Object key:cache.getKeys()) {
|
||||
c+=getMap(key).size();
|
||||
}
|
||||
if(c!=count) {
|
||||
loadDatabase=true;
|
||||
}
|
||||
}
|
||||
if(loadDatabase) {
|
||||
List<ConfigGroupInfo> list=configGroupInfoDao.findAllList(4);
|
||||
Map<Long,Map<Long,ConfigGroupInfo>> groupMap=Maps.newHashMap();
|
||||
for(ConfigGroupInfo configGroupInfo:list) {
|
||||
if(groupMap.containsKey(configGroupInfo.getAsnId()/cache_rage)) {
|
||||
groupMap.get(configGroupInfo.getAsnId()/cache_rage)
|
||||
.put(configGroupInfo.getAsnId(), configGroupInfo);
|
||||
}else {
|
||||
Map<Long,ConfigGroupInfo> m=Maps.newHashMap();
|
||||
m.put(configGroupInfo.getAsnId(), configGroupInfo);
|
||||
groupMap.put(configGroupInfo.getAsnId()/cache_rage, m);
|
||||
}
|
||||
}
|
||||
for(Entry<Long, Map<Long, ConfigGroupInfo>> e:groupMap.entrySet()) {
|
||||
Element element = new Element(e.getKey(), e.getValue());
|
||||
cache.put(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long end=System.currentTimeMillis();
|
||||
logger.warn("AsnCacheUtils init finish,cost:"+(end-start));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user