Showing
1 changed file
with
11 additions
and
12 deletions
@@ -14,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -14,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
14 | 14 | ||
15 | import java.util.*; | 15 | import java.util.*; |
16 | 16 | ||
17 | -public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends AbstractCacheRequestResponse<K, V>> { | 17 | +public abstract class AbstractCacheBean<K extends ICacheRequest, V, T extends AbstractCacheRequestResponse<K, V>> { |
18 | 18 | ||
19 | private static final Logger RECALL_NEW_LOGGER = LoggerFactory.getLogger("RECALL"); | 19 | private static final Logger RECALL_NEW_LOGGER = LoggerFactory.getLogger("RECALL"); |
20 | 20 | ||
@@ -30,14 +30,14 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs | @@ -30,14 +30,14 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs | ||
30 | * @param useEhCache | 30 | * @param useEhCache |
31 | * @return | 31 | * @return |
32 | */ | 32 | */ |
33 | - public void bacthFillResponseWithCache(final List<T> requests, boolean useEhCache,int maxMissRequestCount){ | 33 | + public void bacthFillResponseWithCache(final List<T> requests, boolean useEhCache, int maxMissRequestCount) { |
34 | //1、批量从缓存中获取 | 34 | //1、批量从缓存中获取 |
35 | this.batchFillResponseFromCache(requests, useEhCache); | 35 | this.batchFillResponseFromCache(requests, useEhCache); |
36 | //2、获取未命中缓存的请求 | 36 | //2、获取未命中缓存的请求 |
37 | - List<T> missCacheRequests = this.filterMissCacheRequests(requests,maxMissRequestCount); | 37 | + List<T> missCacheRequests = this.filterMissCacheRequests(requests, maxMissRequestCount); |
38 | //3、如果remainRequests为空,则说明全部命中了缓存,直接返回即可 | 38 | //3、如果remainRequests为空,则说明全部命中了缓存,直接返回即可 |
39 | if (missCacheRequests.isEmpty()) { | 39 | if (missCacheRequests.isEmpty()) { |
40 | - return ; | 40 | + return; |
41 | } | 41 | } |
42 | //4、处理请求 | 42 | //4、处理请求 |
43 | Map<K, V> requestResponseMap = this.queryMissCacheRequestResults(missCacheRequests); | 43 | Map<K, V> requestResponseMap = this.queryMissCacheRequestResults(missCacheRequests); |
@@ -49,6 +49,7 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs | @@ -49,6 +49,7 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs | ||
49 | 49 | ||
50 | /** | 50 | /** |
51 | * 从缓存中批量填充response | 51 | * 从缓存中批量填充response |
52 | + * | ||
52 | * @param cacheRequestResponses | 53 | * @param cacheRequestResponses |
53 | * @param useEhCache | 54 | * @param useEhCache |
54 | */ | 55 | */ |
@@ -75,16 +76,17 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs | @@ -75,16 +76,17 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs | ||
75 | 76 | ||
76 | /** | 77 | /** |
77 | * 过滤出未命中缓存的结果 | 78 | * 过滤出未命中缓存的结果 |
79 | + * | ||
78 | * @param cacheRequestResponses | 80 | * @param cacheRequestResponses |
79 | * @return | 81 | * @return |
80 | */ | 82 | */ |
81 | - private List<T> filterMissCacheRequests(List<T> cacheRequestResponses,int maxMissRequestCount) { | 83 | + private List<T> filterMissCacheRequests(List<T> cacheRequestResponses, int maxMissRequestCount) { |
82 | List<T> notCachedRequests = new ArrayList<>(); | 84 | List<T> notCachedRequests = new ArrayList<>(); |
83 | for (T requestResponse : cacheRequestResponses) { | 85 | for (T requestResponse : cacheRequestResponses) { |
84 | if (requestResponse != null && requestResponse.getResponse() == null) { | 86 | if (requestResponse != null && requestResponse.getResponse() == null) { |
85 | notCachedRequests.add(requestResponse); | 87 | notCachedRequests.add(requestResponse); |
86 | } | 88 | } |
87 | - if(notCachedRequests.size()>=maxMissRequestCount){ | 89 | + if (notCachedRequests.size() >= maxMissRequestCount) { |
88 | break; | 90 | break; |
89 | } | 91 | } |
90 | } | 92 | } |
@@ -101,6 +103,7 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs | @@ -101,6 +103,7 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs | ||
101 | 103 | ||
102 | /** | 104 | /** |
103 | * 使用查询结果填充请求-转成String | 105 | * 使用查询结果填充请求-转成String |
106 | + * | ||
104 | * @param cacheRequestResponses | 107 | * @param cacheRequestResponses |
105 | * @param queryResults | 108 | * @param queryResults |
106 | */ | 109 | */ |
@@ -125,6 +128,7 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs | @@ -125,6 +128,7 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs | ||
125 | 128 | ||
126 | /** | 129 | /** |
127 | * 将未缓存的response添加至缓存 | 130 | * 将未缓存的response添加至缓存 |
131 | + * | ||
128 | * @param cacheRequestResponses | 132 | * @param cacheRequestResponses |
129 | * @param useEhCache | 133 | * @param useEhCache |
130 | */ | 134 | */ |
@@ -138,12 +142,7 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs | @@ -138,12 +142,7 @@ public abstract class AbstractCacheBean<K extends ICacheRequest, V,T extends Abs | ||
138 | }); | 142 | }); |
139 | //2、按缓存时间大小直接加入缓存 | 143 | //2、按缓存时间大小直接加入缓存 |
140 | for (Map.Entry<Integer, List<T>> entry : groupMap.entrySet()) { | 144 | for (Map.Entry<Integer, List<T>> entry : groupMap.entrySet()) { |
141 | - Integer timeOutInSecond = entry.getKey(); | ||
142 | - if(timeOutInSecond!=null && timeOutInSecond>0){ | ||
143 | - this.batchAddResponseToCache(entry.getValue(), useEhCache, timeOutInSecond); | ||
144 | - }else{ | ||
145 | - RECALL_NEW_LOGGER.error("batchAddResponseToCache fail, find illegal timeOutInSecond"); | ||
146 | - } | 145 | + this.batchAddResponseToCache(entry.getValue(), useEhCache, entry.getKey()); |
147 | } | 146 | } |
148 | } | 147 | } |
149 | 148 |
-
Please register or login to post a comment