提交 cb3524ff 编写于 作者: C Costin Leau

+ fix failing cache tests

+ renamed afterInvocation to beforeInvocation (and changed the docs and tests accordingly)
上级 735ba9dc
......@@ -8,6 +8,7 @@ Changes in version 3.1 GA (2011-12-12)
* fixed QuartzJobBean to work with Quartz 2.0/2.1 as well
* added String constants to MediaType
* renamed attribute @CacheEvict#afterInvocation to beforeInvocation (for better readability)
Changes in version 3.1 RC2 (2011-11-28)
......
......@@ -53,7 +53,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
public void evictAll(Object arg1) {
}
@CacheEvict(value = "default", afterInvocation = false)
@CacheEvict(value = "default", beforeInvocation = false)
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 = false)
public void invalidateEarly(Object arg1, Object arg2) {
throw new RuntimeException("exception thrown - evict should still occur");
}
......
......@@ -51,7 +51,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
public void evictAll(Object arg1) {
}
@CacheEvict(value = "default", afterInvocation = false)
@CacheEvict(value = "default", beforeInvocation = false)
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 = false)
public void invalidateEarly(Object arg1, Object arg2) {
throw new RuntimeException("exception thrown - evict should still occur");
}
......
......@@ -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);
}
}
\ No newline at end of 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);
......
......@@ -225,14 +225,14 @@ public abstract class CacheAspectSupport implements InitializingBean {
}
private void inspectBeforeCacheEvicts(Collection<CacheOperationContext> evictions) {
inspectCacheEvicts(evictions, false);
inspectCacheEvicts(evictions, true);
}
private void inspectAfterCacheEvicts(Collection<CacheOperationContext> evictions) {
inspectCacheEvicts(evictions, true);
inspectCacheEvicts(evictions, false);
}
private void inspectCacheEvicts(Collection<CacheOperationContext> evictions, boolean afterInvocation) {
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;
}
}
......@@ -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
......
......@@ -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");
}
......
......@@ -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");
}
......
......@@ -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">
......
......@@ -248,9 +248,9 @@ public void loadBooks(InputStream batch)]]></programlisting>
all the entires are removed in one operation as shown above. Note that the framework will ignore any key specified in this scenario as it does not apply (the entire cache is evicted not just
one entry).</para>
<para>One can also indicate whether the eviction should occur after (the default) or before the method executes (the default) through the <literal>afterInvocation</literal> attribute.
<para>One can also indicate whether the eviction should occur after (the default) or before the method executes through the <literal>beforeInvocation</literal> attribute.
The former provides the same semantics as the rest of the annotations - once the method completes successfully, an action (in this case eviction) on the cache is executed. If the method does not
execute (as it might be cached) or an exception is thrown, the eviction does not occur. The latter (<literal>afterInvocation=false</literal>) causes the eviction to occur always, before the method
execute (as it might be cached) or an exception is thrown, the eviction does not occur. The latter (<literal>beforeInvocation=true</literal>) causes the eviction to occur always, before the method
is invoked - this is useful in cases where the eviction does not need to be tied to the method outcome.</para>
<para>It is important to note that void methods can be used with <literal>@CacheEvict</literal> - as the methods act as triggers, the return values are ignored (as they don't interact with
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册