Authored by hugufei

方法以及变量重命名

... ... @@ -79,16 +79,16 @@ public abstract class AbstractCacheBean<Request extends ICacheRequest, Response,
* @return
*/
private List<RequestResponse> filterMissCacheRequests(List<RequestResponse> requestResponses, int maxMissRequestCount) {
List<RequestResponse> notCachedRequests = new ArrayList<>();
List<RequestResponse> missCacheRequestResponse = new ArrayList<>();
for (RequestResponse requestResponse : requestResponses) {
if (requestResponse != null && requestResponse.getResponse() == null) {
notCachedRequests.add(requestResponse);
missCacheRequestResponse.add(requestResponse);
}
if (notCachedRequests.size() >= maxMissRequestCount) {
if (missCacheRequestResponse.size() >= maxMissRequestCount) {
break;
}
}
return notCachedRequests;
return missCacheRequestResponse;
}
/**
... ... @@ -110,13 +110,15 @@ public abstract class AbstractCacheBean<Request extends ICacheRequest, Response,
* 使用查询结果填充请求-转成String
*
* @param requestResponses
* @param queryResults
* @param requestResponseMap
*/
private void batchFillResponseWithQueryResults(List<RequestResponse> requestResponses, Map<Request, Response> queryResults) {
private void batchFillResponseWithQueryResults(List<RequestResponse> requestResponses, Map<Request, Response> requestResponseMap) {
//1、先转成map
Map<String, Response> toCacheResults = new HashMap<>();
for (Map.Entry<Request, Response> entry : queryResults.entrySet()) {
toCacheResults.put(entry.getKey().redisKeyBuilder().getKey(), entry.getValue());
Map<String, Response> requestKeyResponseMap = new HashMap<>();
for (Map.Entry<Request, Response> requestResponseEntry : requestResponseMap.entrySet()) {
Request request = requestResponseEntry.getKey();
Response response = requestResponseEntry.getValue();
requestKeyResponseMap.put(request.redisKeyBuilder().getKey(), response);
}
//2、填充结果
for (RequestResponse requestResponse : requestResponses) {
... ... @@ -124,7 +126,7 @@ public abstract class AbstractCacheBean<Request extends ICacheRequest, Response,
continue;
}
RedisKeyBuilder redisKeyBuilder = requestResponse.getRequest().redisKeyBuilder();
Response response = toCacheResults.get(redisKeyBuilder.getKey());
Response response = requestKeyResponseMap.get(redisKeyBuilder.getKey());
if (response != null) {
requestResponse.setResponse(response, true);
}
... ... @@ -141,7 +143,11 @@ public abstract class AbstractCacheBean<Request extends ICacheRequest, Response,
Map<Integer, List<RequestResponse>> groupMap = CollectionUtils.toListMap(requestResponses, new Transfer<RequestResponse, Integer>() {
@Override
public Integer transfer(RequestResponse requestResponse) {
return requestResponse.getRequest().cacheTimeInSecond();
Request request = requestResponse.getRequest();
if(request==null){
return 0;
}
return request.cacheTimeInSecond();
}
});
//2、按缓存时间大小直接加入缓存
... ... @@ -157,12 +163,20 @@ public abstract class AbstractCacheBean<Request extends ICacheRequest, Response,
if (!requestResponse.isNeedRecache()) {
continue;
}
RedisKeyBuilder redisKeyBuilder = requestResponse.getRequest().redisKeyBuilder();
Request request = requestResponse.getRequest();
Response response = requestResponse.getResponse();
if (redisKeyBuilder == null || response == null) {
if (request==null || response == null) {
continue;
}
RedisKeyBuilder redisKeyBuilder = request.redisKeyBuilder();
if(redisKeyBuilder == null){
continue;
}
Transfer<Response, String> fromResponseTransfer = requestResponse.getFromResponseTransfer();
if(fromResponseTransfer==null){
continue;
}
String cacheValue = requestResponse.getFromResponseTransfer().transfer(response);
String cacheValue = fromResponseTransfer.transfer(response);
toCacheMap.put(redisKeyBuilder, cacheValue);
}
if (toCacheMap.isEmpty()) {
... ...