报表缓存Key优化,支持以时间为粒度缓存;

LocalCache优化,避免缓存堆积;
pull/6/head
xuxueli 7 years ago
parent a1e11ea190
commit 6ca29c0d17

@ -61,6 +61,11 @@ public class LocalCacheUtil {
* @return
*/
public static boolean set(String key, Object val, long cacheTime){
// clean timeout cache, before set new cache (avoid cache too much)
cleanTimeutCache();
// set new cache
if (StringUtils.isBlank(key)) {
return false;
}
@ -109,4 +114,21 @@ public class LocalCacheUtil {
}
}
/**
* clean timeout cache
*
* @return
*/
public static boolean cleanTimeutCache(){
if (!cacheRepository.keySet().isEmpty()) {
for (String key: cacheRepository.keySet()) {
LocalCacheData localCacheData = cacheRepository.get(key);
if (localCacheData!=null && System.currentTimeMillis()>=localCacheData.getTimeoutTime()) {
cacheRepository.remove(key);
}
}
}
return true;
}
}

@ -325,7 +325,8 @@ public class XxlJobServiceImpl implements XxlJobService {
@Override
public ReturnT<Map<String, Object>> triggerChartDate(Date startDate, Date endDate) {
// get cache
Map<String, Object> triggerChartDateCache = (Map<String, Object>) LocalCacheUtil.get(TRIGGER_CHART_DATA_CACHE);
String cacheKey = TRIGGER_CHART_DATA_CACHE + "_" + startDate.getTime() + "_" + endDate.getTime();
Map<String, Object> triggerChartDateCache = (Map<String, Object>) LocalCacheUtil.get(cacheKey);
if (triggerChartDateCache != null) {
return new ReturnT<Map<String, Object>>(triggerChartDateCache);
}
@ -376,7 +377,7 @@ public class XxlJobServiceImpl implements XxlJobService {
result.put("triggerCountFailTotal", triggerCountFailTotal);
// set cache
LocalCacheUtil.set(TRIGGER_CHART_DATA_CACHE, result, 60*1000); // cache 60s
LocalCacheUtil.set(cacheKey, result, 60*1000); // cache 60s
return new ReturnT<Map<String, Object>>(result);
}

Loading…
Cancel
Save