+ fix failing cache tests

+ renamed afterInvocation to beforeInvocation (and changed the docs and tests accordingly)
This commit is contained in:
Costin Leau
2011-12-06 14:05:33 +00:00
parent 735ba9dcde
commit cb3524ff30
13 changed files with 33 additions and 32 deletions

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -214,7 +214,7 @@
Whether all the entries should be evicted.]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="after-invocation" type="xsd:boolean" use="optional">
<xsd:attribute name="before-invocation" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Whether the eviction should occur after the method is successfully

View File

@@ -53,7 +53,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
public void evictAll(Object arg1) {
}
@CacheEvict(value = "default", afterInvocation = false)
@CacheEvict(value = "default", beforeInvocation = true)
public void evictEarly(Object arg1) {
throw new RuntimeException("exception thrown - evict should still occur");
}
@@ -62,7 +62,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
public void evict(Object arg1, Object arg2) {
}
@CacheEvict(value = "default", key = "#p0", afterInvocation = false)
@CacheEvict(value = "default", key = "#p0", beforeInvocation = true)
public void invalidateEarly(Object arg1, Object arg2) {
throw new RuntimeException("exception thrown - evict should still occur");
}

View File

@@ -51,7 +51,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
public void evictAll(Object arg1) {
}
@CacheEvict(value = "default", afterInvocation = false)
@CacheEvict(value = "default", beforeInvocation = true)
public void evictEarly(Object arg1) {
throw new RuntimeException("exception thrown - evict should still occur");
}
@@ -60,7 +60,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
public void evict(Object arg1, Object arg2) {
}
@CacheEvict(value = "default", key = "#p0", afterInvocation = false)
@CacheEvict(value = "default", key = "#p0", beforeInvocation = true)
public void invalidateEarly(Object arg1, Object arg2) {
throw new RuntimeException("exception thrown - evict should still occur");
}

View File

@@ -20,8 +20,8 @@
<cache:cache-evict method="invalidate" cache="default"/>
<cache:cache-evict method="evict" key="#p0" cache="default"/>
<cache:cache-evict method="evictWithException" cache="default"/>
<cache:cache-evict method="evictEarly" cache="default" after-invocation="false"/>
<cache:cache-evict method="invalidateEarly" key="#p0" cache="default" after-invocation="false"/>
<cache:cache-evict method="evictEarly" cache="default" before-invocation="true"/>
<cache:cache-evict method="invalidateEarly" key="#p0" cache="default" before-invocation="true"/>
<cache:cache-evict method="evictAll" cache="default" all-entries="true"/>
</cache:caching>
<cache:caching cache="default">
@@ -60,8 +60,8 @@
<cache:cache-evict method="invalidate" cache="default"/>
<cache:cache-evict method="evict" key="#p0" cache="default"/>
<cache:cache-evict method="evictWithException" cache="default"/>
<cache:cache-evict method="evictEarly" cache="default" after-invocation="false"/>
<cache:cache-evict method="invalidateEarly" key="#p0" cache="default" after-invocation="false"/>
<cache:cache-evict method="evictEarly" cache="default" before-invocation="true"/>
<cache:cache-evict method="invalidateEarly" key="#p0" cache="default" before-invocation="true"/>
<cache:cache-evict method="evictAll" cache="default" all-entries="true"/>
</cache:caching>
<cache:caching cache="default">