Authored by mali

缓存细化

... ... @@ -52,7 +52,8 @@ public interface CacheClient {
* @param <T> 类型
* @return key-response的map
*/
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);
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);
/**
... ...
... ... @@ -246,17 +246,18 @@ public class RedisGwCacheClient implements CacheClient {
result.put(redisKeyBuilders.get(i).getKey(), JSON.parseObject(curItem, clazz));
}
}
Map<K, T> lastResult = new HashMap<>();
Map<K, T> apply = nullCacheFun.apply(nullCachekeys); // 执行回调函数去数据库查询未缓存的键值集合
for(Map.Entry<K, T> item : apply.entrySet()) {
result.put(String.valueOf(item.getKey()), item.getValue());
lastResult.put(item.getKey(), item.getValue());
}
setBulk(apply, timeOut, cacheKeyPre, clazz); // 将不在缓存的键值对批量放入缓存
Map<K, T> lastResult = new HashMap<>();
for(Map.Entry<String, T> entry : result.entrySet()) {
lastResult.put(keyConvertFun.apply(entry.getKey()), entry.getValue());
lastResult.put(cacheKeyAndStringMap.get(entry.getKey()), entry.getValue());
}
return lastResult;
... ...