+ fix failing cache tests
+ renamed afterInvocation to beforeInvocation (and changed the docs and tests accordingly)
This commit is contained in:
@@ -68,5 +68,5 @@ public @interface CacheEvict {
|
||||
* or before. The latter causes the eviction to occur irrespective of the method outcome (whether
|
||||
* it threw an exception or not) while the former does not.
|
||||
*/
|
||||
boolean afterInvocation() default true;
|
||||
boolean beforeInvocation() default false;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
|
||||
ceo.setCondition(caching.condition());
|
||||
ceo.setKey(caching.key());
|
||||
ceo.setCacheWide(caching.allEntries());
|
||||
ceo.setAfterInvocation(caching.afterInvocation());
|
||||
ceo.setBeforeInvocation(caching.beforeInvocation());
|
||||
ceo.setName(ae.toString());
|
||||
return ceo;
|
||||
}
|
||||
@@ -152,6 +152,6 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
|
||||
}
|
||||
}
|
||||
|
||||
return anns;
|
||||
return (anns.isEmpty() ? null : anns);
|
||||
}
|
||||
}
|
||||
@@ -188,9 +188,9 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
|
||||
op.setCacheWide(Boolean.valueOf(wide.trim()));
|
||||
}
|
||||
|
||||
String after = opElement.getAttribute("after-invocation");
|
||||
String after = opElement.getAttribute("before-invocation");
|
||||
if (StringUtils.hasText(after)) {
|
||||
op.setAfterInvocation(Boolean.valueOf(after.trim()));
|
||||
op.setBeforeInvocation(Boolean.valueOf(after.trim()));
|
||||
}
|
||||
|
||||
Collection<CacheOperation> col = cacheOpMap.get(nameHolder);
|
||||
|
||||
@@ -225,14 +225,14 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
||||
}
|
||||
|
||||
private void inspectBeforeCacheEvicts(Collection<CacheOperationContext> evictions) {
|
||||
inspectCacheEvicts(evictions, false);
|
||||
}
|
||||
|
||||
private void inspectAfterCacheEvicts(Collection<CacheOperationContext> evictions) {
|
||||
inspectCacheEvicts(evictions, true);
|
||||
}
|
||||
|
||||
private void inspectCacheEvicts(Collection<CacheOperationContext> evictions, boolean afterInvocation) {
|
||||
private void inspectAfterCacheEvicts(Collection<CacheOperationContext> evictions) {
|
||||
inspectCacheEvicts(evictions, false);
|
||||
}
|
||||
|
||||
private void inspectCacheEvicts(Collection<CacheOperationContext> evictions, boolean beforeInvocation) {
|
||||
|
||||
if (!evictions.isEmpty()) {
|
||||
|
||||
@@ -241,7 +241,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
||||
for (CacheOperationContext context : evictions) {
|
||||
CacheEvictOperation evictOp = (CacheEvictOperation) context.operation;
|
||||
|
||||
if (afterInvocation == evictOp.isAfterInvocation()) {
|
||||
if (beforeInvocation == evictOp.isBeforeInvocation()) {
|
||||
if (context.isConditionPassing()) {
|
||||
// for each cache
|
||||
// lazy key initialization
|
||||
|
||||
@@ -25,7 +25,7 @@ package org.springframework.cache.interceptor;
|
||||
public class CacheEvictOperation extends CacheOperation {
|
||||
|
||||
private boolean cacheWide = false;
|
||||
private boolean afterInvocation = true;
|
||||
private boolean beforeInvocation = false;
|
||||
|
||||
public void setCacheWide(boolean cacheWide) {
|
||||
this.cacheWide = cacheWide;
|
||||
@@ -35,12 +35,12 @@ public class CacheEvictOperation extends CacheOperation {
|
||||
return this.cacheWide;
|
||||
}
|
||||
|
||||
public void setAfterInvocation(boolean afterInvocation) {
|
||||
this.afterInvocation = afterInvocation;
|
||||
public void setBeforeInvocation(boolean beforeInvocation) {
|
||||
this.beforeInvocation = beforeInvocation;
|
||||
}
|
||||
|
||||
public boolean isAfterInvocation() {
|
||||
return this.afterInvocation;
|
||||
public boolean isBeforeInvocation() {
|
||||
return this.beforeInvocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,7 +49,7 @@ public class CacheEvictOperation extends CacheOperation {
|
||||
sb.append(",");
|
||||
sb.append(this.cacheWide);
|
||||
sb.append(",");
|
||||
sb.append(this.afterInvocation);
|
||||
sb.append(this.beforeInvocation);
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user