use of cn.taketoday.cache.CacheValueRetrievalException in project today-framework by TAKETODAY.
the class CacheableInterceptor method invoke.
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
MethodKey methodKey = new MethodKey(method, Cacheable.class);
CacheConfiguration cacheable = expressionOperations.getConfig(methodKey);
CacheEvaluationContext context = expressionOperations.prepareContext(methodKey, invocation);
if (expressionOperations.passCondition(cacheable.condition(), context)) {
// pass the condition
Cache cache = obtainCache(method, cacheable);
Object key = expressionOperations.createKey(cacheable.key(), context, invocation);
if (cacheable.sync()) {
// for sync
try {
return cache.get(key, invocation::proceed);
} catch (CacheValueRetrievalException e) {
throw e.getCause();
}
} else {
Object value = get(cache, key);
if (value == null) {
value = invocation.proceed();
if (expressionOperations.allowPutCache(cacheable.unless(), value, context)) {
put(cache, key, value);
}
}
return value;
}
}
return invocation.proceed();
}
Aggregations