|
|
|
@ -24,12 +24,9 @@ import org.apache.dolphinscheduler.service.cache.impl.CacheKeyGenerator;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
|
|
|
import java.lang.annotation.Annotation; |
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
|
|
|
import org.aspectj.lang.annotation.Around; |
|
|
|
@ -39,7 +36,6 @@ import org.aspectj.lang.reflect.MethodSignature;
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.boot.context.properties.bind.Name; |
|
|
|
|
import org.springframework.cache.annotation.CacheConfig; |
|
|
|
|
import org.springframework.cache.annotation.CacheEvict; |
|
|
|
|
import org.springframework.expression.EvaluationContext; |
|
|
|
@ -61,6 +57,11 @@ public class CacheEvictAspect {
|
|
|
|
|
*/ |
|
|
|
|
private static final String EL_SYMBOL = "#"; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* prefix of spring el |
|
|
|
|
*/ |
|
|
|
|
private static final String P = "p"; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private CacheKeyGenerator cacheKeyGenerator; |
|
|
|
|
|
|
|
|
@ -91,9 +92,8 @@ public class CacheEvictAspect {
|
|
|
|
|
cacheKey = (String) cacheKeyGenerator.generate(target, method, args); |
|
|
|
|
} else { |
|
|
|
|
cacheKey = cacheEvict.key(); |
|
|
|
|
List<Name> paramsList = getParamAnnotationsByType(method, Name.class); |
|
|
|
|
if (cacheEvict.key().contains(EL_SYMBOL)) { |
|
|
|
|
cacheKey = parseKey(cacheEvict.key(), paramsList.stream().map(o -> o.value()).collect(Collectors.toList()), Arrays.asList(args)); |
|
|
|
|
cacheKey = parseKey(cacheEvict.key(), Arrays.asList(args)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isNotEmpty(cacheKey)) { |
|
|
|
@ -123,11 +123,11 @@ public class CacheEvictAspect {
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String parseKey(String key, List<String> paramNameList, List<Object> paramList) { |
|
|
|
|
private String parseKey(String key, List<Object> paramList) { |
|
|
|
|
SpelExpressionParser spelParser = new SpelExpressionParser(); |
|
|
|
|
EvaluationContext ctx = new StandardEvaluationContext(); |
|
|
|
|
for (int i = 0; i < paramNameList.size(); i++) { |
|
|
|
|
ctx.setVariable("p" + i, paramList.get(i)); |
|
|
|
|
for (int i = 0; i < paramList.size(); i++) { |
|
|
|
|
ctx.setVariable(P + i, paramList.get(i)); |
|
|
|
|
} |
|
|
|
|
Object obj = spelParser.parseExpression(key).getValue(ctx); |
|
|
|
|
if (null == obj) { |
|
|
|
@ -135,18 +135,4 @@ public class CacheEvictAspect {
|
|
|
|
|
} |
|
|
|
|
return obj.toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private <T extends Annotation> List<T> getParamAnnotationsByType(Method method, Class<T> annotationClass) { |
|
|
|
|
List<T> annotationsList = new ArrayList<>(); |
|
|
|
|
Annotation[][] annotations = method.getParameterAnnotations(); |
|
|
|
|
for (int i = 0; i < annotations.length; i++) { |
|
|
|
|
Annotation[] annotationsI = annotations[i]; |
|
|
|
|
for (Annotation annotation : annotationsI) { |
|
|
|
|
if (annotation.annotationType().equals(annotationClass)) { |
|
|
|
|
annotationsList.add((T) annotation); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return annotationsList; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|