diff --git a/build-spring-framework/resources/changelog.txt b/build-spring-framework/resources/changelog.txt index 29f77a493e..af884f9b65 100644 --- a/build-spring-framework/resources/changelog.txt +++ b/build-spring-framework/resources/changelog.txt @@ -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) diff --git a/org.springframework.aspects/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java b/org.springframework.aspects/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java index 2db724f6f1..8a5a4da9e9 100644 --- a/org.springframework.aspects/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java +++ b/org.springframework.aspects/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java @@ -53,7 +53,7 @@ public class AnnotatedClassCacheableService implements CacheableService 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 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"); } diff --git a/org.springframework.aspects/src/test/java/org/springframework/cache/config/DefaultCacheableService.java b/org.springframework.aspects/src/test/java/org/springframework/cache/config/DefaultCacheableService.java index aeabc9a046..65ec02f293 100644 --- a/org.springframework.aspects/src/test/java/org/springframework/cache/config/DefaultCacheableService.java +++ b/org.springframework.aspects/src/test/java/org/springframework/cache/config/DefaultCacheableService.java @@ -51,7 +51,7 @@ public class DefaultCacheableService implements CacheableService { 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 { 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"); } diff --git a/org.springframework.context/src/main/java/org/springframework/cache/annotation/CacheEvict.java b/org.springframework.context/src/main/java/org/springframework/cache/annotation/CacheEvict.java index 6a38e03ab5..b46367f670 100644 --- a/org.springframework.context/src/main/java/org/springframework/cache/annotation/CacheEvict.java +++ b/org.springframework.context/src/main/java/org/springframework/cache/annotation/CacheEvict.java @@ -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; } diff --git a/org.springframework.context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java b/org.springframework.context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java index ab26c40092..07280ead2b 100644 --- a/org.springframework.context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java +++ b/org.springframework.context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java @@ -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 diff --git a/org.springframework.context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java b/org.springframework.context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java index df40c82db6..a1206c576f 100644 --- a/org.springframework.context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java +++ b/org.springframework.context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java @@ -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 col = cacheOpMap.get(nameHolder); diff --git a/org.springframework.context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java b/org.springframework.context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java index ea0cc2b4ed..1a600193b9 100644 --- a/org.springframework.context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java +++ b/org.springframework.context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java @@ -225,14 +225,14 @@ public abstract class CacheAspectSupport implements InitializingBean { } private void inspectBeforeCacheEvicts(Collection evictions) { - inspectCacheEvicts(evictions, false); - } - - private void inspectAfterCacheEvicts(Collection evictions) { inspectCacheEvicts(evictions, true); } - private void inspectCacheEvicts(Collection evictions, boolean afterInvocation) { + private void inspectAfterCacheEvicts(Collection evictions) { + inspectCacheEvicts(evictions, false); + } + + private void inspectCacheEvicts(Collection 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 diff --git a/org.springframework.context/src/main/java/org/springframework/cache/interceptor/CacheEvictOperation.java b/org.springframework.context/src/main/java/org/springframework/cache/interceptor/CacheEvictOperation.java index 203aa0164d..62186d8966 100644 --- a/org.springframework.context/src/main/java/org/springframework/cache/interceptor/CacheEvictOperation.java +++ b/org.springframework.context/src/main/java/org/springframework/cache/interceptor/CacheEvictOperation.java @@ -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; } } diff --git a/org.springframework.context/src/main/resources/org/springframework/cache/config/spring-cache-3.1.xsd b/org.springframework.context/src/main/resources/org/springframework/cache/config/spring-cache-3.1.xsd index ff3c3746ee..eab936d9ab 100644 --- a/org.springframework.context/src/main/resources/org/springframework/cache/config/spring-cache-3.1.xsd +++ b/org.springframework.context/src/main/resources/org/springframework/cache/config/spring-cache-3.1.xsd @@ -214,7 +214,7 @@ Whether all the entries should be evicted.]]> - + 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 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"); } diff --git a/org.springframework.context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java b/org.springframework.context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java index 034df1143a..0f7493c554 100644 --- a/org.springframework.context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java +++ b/org.springframework.context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java @@ -51,7 +51,7 @@ public class DefaultCacheableService implements CacheableService { 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 { 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"); } diff --git a/org.springframework.context/src/test/resources/org/springframework/cache/config/cache-advice.xml b/org.springframework.context/src/test/resources/org/springframework/cache/config/cache-advice.xml index ec36d11ffa..36201c291d 100644 --- a/org.springframework.context/src/test/resources/org/springframework/cache/config/cache-advice.xml +++ b/org.springframework.context/src/test/resources/org/springframework/cache/config/cache-advice.xml @@ -20,8 +20,8 @@ - - + + @@ -60,8 +60,8 @@ - - + + diff --git a/spring-framework-reference/src/cache.xml b/spring-framework-reference/src/cache.xml index 4bfab4d63b..f3d8b337c8 100644 --- a/spring-framework-reference/src/cache.xml +++ b/spring-framework-reference/src/cache.xml @@ -248,9 +248,9 @@ public void loadBooks(InputStream batch)]]> 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). - One can also indicate whether the eviction should occur after (the default) or before the method executes (the default) through the afterInvocation attribute. + One can also indicate whether the eviction should occur after (the default) or before the method executes through the beforeInvocation 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 (afterInvocation=false) 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 (beforeInvocation=true) 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. It is important to note that void methods can be used with @CacheEvict - as the methods act as triggers, the return values are ignored (as they don't interact with