Map<String, Object> cacheResults = getBulkFromCache(keys);
AddableObject<T> addableObj = new AddableObject<T>(keys.size(), mappedClass);
int hitCapacity = cacheResults != null ? cacheResults.size() : 0;
List<U> hitSuffix = new ArrayList<U>(hitCapacity); // 用于debug
Set<U> missSuffix = new HashSet<U>((keys.size() - hitCapacity) * 2);
for (Object suffix : new Iterables(getSuffixObj(context))) {
String key = getCacheKey(suffix);
Object value = cacheResults != null ? cacheResults.get(key) : null;
if (value == null) {
missSuffix.add(suffixClass.cast(suffix));
} else {
addableObj.add(mappedClass.cast(value));
if (isDebugEnabled) {
hitSuffix.add(suffixClass.cast(suffix));
}
}
}
if (isDebugEnabled) {
logger.debug("cache hit #keys={} #values={}", hitSuffix, addableObj);
logger.debug("cache miss #keys={}", missSuffix);
}
if (!missSuffix.isEmpty()) { // 有key没有命中
setSuffixObj(context, missSuffix);
Object dbValues = executeFromDb(context);
for (Object dbValue : new Iterables(dbValues)) {
// db数据添加入结果
addableObj.add(mappedClass.cast(dbValue));
// 添加入缓存
Object suffix = BeanUtil.getPropertyValue(dbValue, interableProperty, mappedClass);
String key = getCacheKey(suffix);