SPR-8007
SPR-7832 + expose the invocation params through the cache root object + update javadocs
This commit is contained in:
@@ -141,8 +141,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
||||
}
|
||||
|
||||
protected CacheOperationContext getOperationContext(CacheDefinition definition, Method method, Object[] args,
|
||||
Class<?> targetClass) {
|
||||
return new CacheOperationContext(definition, method, args, targetClass);
|
||||
Object target, Class<?> targetClass) {
|
||||
return new CacheOperationContext(definition, method, args, target, targetClass);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -160,7 +160,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
||||
|
||||
// analyze caching information
|
||||
if (cacheDef != null) {
|
||||
CacheOperationContext context = getOperationContext(cacheDef, method, args, targetClass);
|
||||
CacheOperationContext context = getOperationContext(cacheDef, method, args, target, targetClass);
|
||||
Collection<Cache<?, ?>> caches = context.getCaches();
|
||||
|
||||
if (context.hasConditionPassed()) {
|
||||
@@ -277,13 +277,13 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
||||
private final KeyGenerator<?> keyGenerator = CacheAspectSupport.this.keyGenerator;
|
||||
|
||||
public CacheOperationContext(CacheDefinition operationDefinition, Method method, Object[] args,
|
||||
Class<?> targetClass) {
|
||||
Object target, Class<?> targetClass) {
|
||||
this.definition = operationDefinition;
|
||||
this.caches = CacheAspectSupport.this.getCaches(definition);
|
||||
this.method = method;
|
||||
this.args = args;
|
||||
|
||||
this.evalContext = evaluator.createEvaluationContext(caches, method, args, targetClass);
|
||||
this.evalContext = evaluator.createEvaluationContext(caches, method, args, target, targetClass);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cache.interceptor;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
@@ -34,6 +35,34 @@ interface CacheExpressionRootObject {
|
||||
*/
|
||||
String getMethodName();
|
||||
|
||||
/**
|
||||
* Returns the method being cached.
|
||||
*
|
||||
* @return method being cached
|
||||
*/
|
||||
Method getMethod();
|
||||
|
||||
/**
|
||||
* Returns the parameters for this invocation.
|
||||
*
|
||||
* @return params for this invocation.
|
||||
*/
|
||||
Object[] getParams();
|
||||
|
||||
/**
|
||||
* Returns the target instance being cached.
|
||||
*
|
||||
* @return target instance
|
||||
*/
|
||||
Object getTarget();
|
||||
|
||||
/**
|
||||
* Returns the target class.
|
||||
*
|
||||
* @return target class
|
||||
*/
|
||||
Class<?> getTargetClass();
|
||||
|
||||
/**
|
||||
* Returns the caches against which the method is executed.
|
||||
*
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cache.interceptor;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
@@ -28,12 +29,22 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class DefaultCacheExpressionRootObject implements CacheExpressionRootObject {
|
||||
|
||||
private final Object target;
|
||||
private final Class<?> targetClass;
|
||||
private final String methodName;
|
||||
private final Method method;
|
||||
private final Collection<Cache<?, ?>> caches;
|
||||
private final Object[] args;
|
||||
|
||||
public DefaultCacheExpressionRootObject(Collection<Cache<?,?>> caches, String methodName) {
|
||||
Assert.hasText(methodName, "method name is required");
|
||||
this.methodName = methodName;
|
||||
public DefaultCacheExpressionRootObject(Collection<Cache<?, ?>> caches, Method method, Object[] args,
|
||||
Object target, Class<?> targetClass) {
|
||||
Assert.notNull(method, "method is required");
|
||||
Assert.notNull(targetClass, "targetClass is required");
|
||||
this.method = method;
|
||||
this.methodName = method.getName();
|
||||
this.target = target;
|
||||
this.targetClass = targetClass;
|
||||
this.args = args;
|
||||
this.caches = caches;
|
||||
}
|
||||
|
||||
@@ -44,4 +55,20 @@ public class DefaultCacheExpressionRootObject implements CacheExpressionRootObje
|
||||
public Collection<Cache<?, ?>> getCaches() {
|
||||
return caches;
|
||||
}
|
||||
|
||||
public Method getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public Object[] getParams() {
|
||||
return args;
|
||||
}
|
||||
|
||||
public Object getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public Class<?> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,8 +47,10 @@ class ExpressionEvaluator {
|
||||
private Map<Method, Expression> keyCache = new ConcurrentHashMap<Method, Expression>();
|
||||
private Map<Method, Method> targetMethodCache = new ConcurrentHashMap<Method, Method>();
|
||||
|
||||
EvaluationContext createEvaluationContext(Collection<Cache<?, ?>> caches, Method method, Object[] args, Class<?> targetClass) {
|
||||
DefaultCacheExpressionRootObject rootObject = new DefaultCacheExpressionRootObject(caches, method.getName());
|
||||
EvaluationContext createEvaluationContext(Collection<Cache<?, ?>> caches, Method method, Object[] args,
|
||||
Object target, Class<?> targetClass) {
|
||||
DefaultCacheExpressionRootObject rootObject = new DefaultCacheExpressionRootObject(caches, method, args,
|
||||
target, targetClass);
|
||||
StandardEvaluationContext evaluationContext = new LazyParamAwareEvaluationContext(rootObject,
|
||||
paramNameDiscoverer, method, args, targetClass, targetMethodCache);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user