in jetcache-anno/src/main/java/com/alicp/jetcache/anno/method/CacheHandler.java [183:229]
private static void doUpdate(CacheInvokeContext context, CacheUpdateAnnoConfig updateAnnoConfig) {
Cache cache = context.getCacheFunction().apply(context, updateAnnoConfig);
if (cache == null) {
return;
}
boolean condition = ExpressionUtil.evalCondition(context, updateAnnoConfig);
if (!condition) {
return;
}
Object key = ExpressionUtil.evalKey(context, updateAnnoConfig);
Object value = ExpressionUtil.evalValue(context, updateAnnoConfig);
if (key == null || value == ExpressionUtil.EVAL_FAILED) {
return;
}
if (updateAnnoConfig.isMulti()) {
if (value == null) {
return;
}
Iterable keyIt = toIterable(key);
Iterable valueIt = toIterable(value);
if (keyIt == null) {
logger.error("jetcache @CacheUpdate key is not instance of Iterable or array: " + updateAnnoConfig.getDefineMethod());
return;
}
if (valueIt == null) {
logger.error("jetcache @CacheUpdate value is not instance of Iterable or array: " + updateAnnoConfig.getDefineMethod());
return;
}
List keyList = new ArrayList();
List valueList = new ArrayList();
keyIt.forEach(o -> keyList.add(o));
valueIt.forEach(o -> valueList.add(o));
if (keyList.size() != valueList.size()) {
logger.error("jetcache @CacheUpdate key size not equals with value size: " + updateAnnoConfig.getDefineMethod());
return;
} else {
Map m = new HashMap();
for (int i = 0; i < valueList.size(); i++) {
m.put(keyList.get(i), valueList.get(i));
}
cache.putAll(m);
}
} else {
cache.put(key, value);
}
}