Authored by hugufei

revert

... ... @@ -14,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends AbstractCacheRequestResponse<K, V>> {
public abstract class AbstractCacheBean<K extends ICacheRequest, V, T extends AbstractCacheRequestResponse<K, V>> {
private static final Logger RECALL_NEW_LOGGER = LoggerFactory.getLogger("RECALL");
... ... @@ -30,14 +30,14 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs
* @param useEhCache
* @return
*/
public void bacthFillResponseWithCache(final List<T> requests, boolean useEhCache,int maxMissRequestCount){
public void bacthFillResponseWithCache(final List<T> requests, boolean useEhCache, int maxMissRequestCount) {
//1、批量从缓存中获取
this.batchFillResponseFromCache(requests, useEhCache);
//2、获取未命中缓存的请求
List<T> missCacheRequests = this.filterMissCacheRequests(requests,maxMissRequestCount);
List<T> missCacheRequests = this.filterMissCacheRequests(requests, maxMissRequestCount);
//3、如果remainRequests为空,则说明全部命中了缓存,直接返回即可
if (missCacheRequests.isEmpty()) {
return ;
return;
}
//4、处理请求
Map<K, V> requestResponseMap = this.queryMissCacheRequestResults(missCacheRequests);
... ... @@ -49,6 +49,7 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs
/**
* 从缓存中批量填充response
*
* @param cacheRequestResponses
* @param useEhCache
*/
... ... @@ -75,16 +76,17 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs
/**
* 过滤出未命中缓存的结果
*
* @param cacheRequestResponses
* @return
*/
private List<T> filterMissCacheRequests(List<T> cacheRequestResponses,int maxMissRequestCount) {
private List<T> filterMissCacheRequests(List<T> cacheRequestResponses, int maxMissRequestCount) {
List<T> notCachedRequests = new ArrayList<>();
for (T requestResponse : cacheRequestResponses) {
if (requestResponse != null && requestResponse.getResponse() == null) {
notCachedRequests.add(requestResponse);
}
if(notCachedRequests.size()>=maxMissRequestCount){
if (notCachedRequests.size() >= maxMissRequestCount) {
break;
}
}
... ... @@ -101,6 +103,7 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs
/**
* 使用查询结果填充请求-转成String
*
* @param cacheRequestResponses
* @param queryResults
*/
... ... @@ -125,6 +128,7 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs
/**
* 将未缓存的response添加至缓存
*
* @param cacheRequestResponses
* @param useEhCache
*/
... ... @@ -138,12 +142,7 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs
});
//2、按缓存时间大小直接加入缓存
for (Map.Entry<Integer, List<T>> entry : groupMap.entrySet()) {
Integer timeOutInSecond = entry.getKey();
if(timeOutInSecond!=null && timeOutInSecond>0){
this.batchAddResponseToCache(entry.getValue(), useEhCache, timeOutInSecond);
}else{
RECALL_NEW_LOGGER.error("batchAddResponseToCache fail, find illegal timeOutInSecond");
}
this.batchAddResponseToCache(entry.getValue(), useEhCache, entry.getKey());
}
}
... ...