+ fix internal cache causing the multiple annotations key/conditions to overlap
This commit is contained in:
Costin Leau
2011-11-30 15:21:09 +00:00
parent 91c14bd1fe
commit 0a611aa776
8 changed files with 48 additions and 24 deletions

View File

@@ -225,14 +225,14 @@ public abstract class CacheAspectSupport implements InitializingBean {
}
private void inspectBeforeCacheEvicts(Collection<CacheOperationContext> evictions) {
inspectAfterCacheEvicts(evictions, false);
inspectCacheEvicts(evictions, false);
}
private void inspectAfterCacheEvicts(Collection<CacheOperationContext> evictions) {
inspectAfterCacheEvicts(evictions, true);
inspectCacheEvicts(evictions, true);
}
private void inspectAfterCacheEvicts(Collection<CacheOperationContext> evictions, boolean afterInvocation) {
private void inspectCacheEvicts(Collection<CacheOperationContext> evictions, boolean afterInvocation) {
if (!evictions.isEmpty()) {
@@ -276,8 +276,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
}
private CacheStatus inspectCacheables(Collection<CacheOperationContext> cacheables) {
Map<CacheOperationContext, Object> cUpdates = new LinkedHashMap<CacheOperationContext, Object>(
cacheables.size());
Map<CacheOperationContext, Object> cUpdates = new LinkedHashMap<CacheOperationContext, Object>(cacheables.size());
boolean updateRequire = false;
Object retVal = null;
@@ -439,8 +438,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
// context passed around to avoid multiple creations
private final EvaluationContext evalContext;
public CacheOperationContext(CacheOperation operation, Method method, Object[] args, Object target,
Class<?> targetClass) {
public CacheOperationContext(CacheOperation operation, Method method, Object[] args, Object target, Class<?> targetClass) {
this.operation = operation;
this.caches = CacheAspectSupport.this.getCaches(operation);
this.target = target;
@@ -472,4 +470,4 @@ public abstract class CacheAspectSupport implements InitializingBean {
return this.caches;
}
}
}
}

View File

@@ -114,7 +114,8 @@ public abstract class CacheOperation {
*/
protected StringBuilder getOperationDescription() {
StringBuilder result = new StringBuilder();
result.append("CacheOperation[");
result.append(getClass().getSimpleName());
result.append("[");
result.append(this.name);
result.append("] caches=");
result.append(this.cacheNames);

View File

@@ -44,11 +44,11 @@ class ExpressionEvaluator {
// shared param discoverer since it caches data internally
private ParameterNameDiscoverer paramNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
private Map<Method, Expression> conditionCache = new ConcurrentHashMap<Method, Expression>();
private Map<String, Expression> conditionCache = new ConcurrentHashMap<String, Expression>();
private Map<Method, Expression> keyCache = new ConcurrentHashMap<Method, Expression>();
private Map<String, Expression> keyCache = new ConcurrentHashMap<String, Expression>();
private Map<Method, Method> targetMethodCache = new ConcurrentHashMap<Method, Method>();
private Map<String, Method> targetMethodCache = new ConcurrentHashMap<String, Method>();
public EvaluationContext createEvaluationContext(
@@ -61,21 +61,32 @@ class ExpressionEvaluator {
}
public boolean condition(String conditionExpression, Method method, EvaluationContext evalContext) {
Expression condExp = this.conditionCache.get(method);
String key = toString(method, conditionExpression);
Expression condExp = this.conditionCache.get(key);
if (condExp == null) {
condExp = this.parser.parseExpression(conditionExpression);
this.conditionCache.put(method, condExp);
this.conditionCache.put(key, condExp);
}
return condExp.getValue(evalContext, boolean.class);
}
public Object key(String keyExpression, Method method, EvaluationContext evalContext) {
Expression keyExp = this.keyCache.get(method);
String key = toString(method, keyExpression);
Expression keyExp = this.keyCache.get(key);
if (keyExp == null) {
keyExp = this.parser.parseExpression(keyExpression);
this.keyCache.put(method, keyExp);
this.keyCache.put(key, keyExp);
}
return keyExp.getValue(evalContext);
}
}
private String toString(Method method, String expression) {
StringBuilder sb = new StringBuilder();
sb.append(method.getDeclaringClass().getName());
sb.append("#");
sb.append(method.toString());
sb.append("#");
sb.append(expression);
return sb.toString();
}
}

View File

@@ -45,13 +45,13 @@ class LazyParamAwareEvaluationContext extends StandardEvaluationContext {
private final Class<?> targetClass;
private final Map<Method, Method> methodCache;
private final Map<String, Method> methodCache;
private boolean paramLoaded = false;
LazyParamAwareEvaluationContext(Object rootObject, ParameterNameDiscoverer paramDiscoverer, Method method,
Object[] args, Class<?> targetClass, Map<Method, Method> methodCache) {
Object[] args, Class<?> targetClass, Map<String, Method> methodCache) {
super(rootObject);
this.paramDiscoverer = paramDiscoverer;
@@ -85,13 +85,14 @@ class LazyParamAwareEvaluationContext extends StandardEvaluationContext {
return;
}
Method targetMethod = this.methodCache.get(this.method);
String mKey = toString(this.method);
Method targetMethod = this.methodCache.get(mKey);
if (targetMethod == null) {
targetMethod = AopUtils.getMostSpecificMethod(this.method, this.targetClass);
if (targetMethod == null) {
targetMethod = this.method;
}
this.methodCache.put(this.method, targetMethod);
this.methodCache.put(mKey, targetMethod);
}
// save arguments as indexed variables
@@ -108,4 +109,11 @@ class LazyParamAwareEvaluationContext extends StandardEvaluationContext {
}
}
}
private String toString(Method m) {
StringBuilder sb = new StringBuilder();
sb.append(m.getDeclaringClass().getName());
sb.append("#");
sb.append(m.toString());
return sb.toString();
}
}