Authored by mali

缓存细化

@@ -52,7 +52,8 @@ public interface CacheClient { @@ -52,7 +52,8 @@ public interface CacheClient {
52 * @param <T> 类型 52 * @param <T> 类型
53 * @return key-response的map 53 * @return key-response的map
54 */ 54 */
55 - public <K, T> Map<K, T> getBulk(List<RedisKeyBuilder> keys, Class<T> clazz, Function<List<K>, Map<K, T>> nullCacheFun, Function<String, K> keyConvertFun, long timeOut, String cacheKeyPre, Map<String, K> cacheKeyAndStringMap); 55 + public <K, T> Map<K, T> getBulk(List<RedisKeyBuilder> keys, Class<T> clazz, Function<List<K>, Map<K, T>> nullCacheFun, Function<String, K> keyConvertFun,
  56 + long timeOut, String cacheKeyPre, Map<String, K> cacheKeyAndStringMap);
56 57
57 58
58 /** 59 /**
@@ -246,17 +246,18 @@ public class RedisGwCacheClient implements CacheClient { @@ -246,17 +246,18 @@ public class RedisGwCacheClient implements CacheClient {
246 result.put(redisKeyBuilders.get(i).getKey(), JSON.parseObject(curItem, clazz)); 246 result.put(redisKeyBuilders.get(i).getKey(), JSON.parseObject(curItem, clazz));
247 } 247 }
248 } 248 }
  249 + Map<K, T> lastResult = new HashMap<>();
249 250
250 Map<K, T> apply = nullCacheFun.apply(nullCachekeys); // 执行回调函数去数据库查询未缓存的键值集合 251 Map<K, T> apply = nullCacheFun.apply(nullCachekeys); // 执行回调函数去数据库查询未缓存的键值集合
  252 +
251 for(Map.Entry<K, T> item : apply.entrySet()) { 253 for(Map.Entry<K, T> item : apply.entrySet()) {
252 - result.put(String.valueOf(item.getKey()), item.getValue()); 254 + lastResult.put(item.getKey(), item.getValue());
253 } 255 }
254 256
255 setBulk(apply, timeOut, cacheKeyPre, clazz); // 将不在缓存的键值对批量放入缓存 257 setBulk(apply, timeOut, cacheKeyPre, clazz); // 将不在缓存的键值对批量放入缓存
256 258
257 - Map<K, T> lastResult = new HashMap<>();  
258 for(Map.Entry<String, T> entry : result.entrySet()) { 259 for(Map.Entry<String, T> entry : result.entrySet()) {
259 - lastResult.put(keyConvertFun.apply(entry.getKey()), entry.getValue()); 260 + lastResult.put(cacheKeyAndStringMap.get(entry.getKey()), entry.getValue());
260 } 261 }
261 262
262 return lastResult; 263 return lastResult;