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 1b033832096..2937c074b0f 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 @@ -117,7 +117,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser { private static final String CACHE_EVICT_ELEMENT = "cache-evict"; private static final String CACHE_PUT_ELEMENT = "cache-put"; private static final String METHOD_ATTRIBUTE = "method"; - private static final String DEFS_ELEMENT = "definitions"; + private static final String DEFS_ELEMENT = "caching"; @Override protected Class getBeanClass(Element element) { 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 d633418686a..009eb7a91c0 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 @@ -124,7 +124,7 @@ - + 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 6af65ab73d6..faa231b4105 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 @@ -8,58 +8,58 @@ http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> - + - - + + - - + + - - + + - - + + - - + + - + - + - - + + - - + + - - + + @@ -70,7 +70,7 @@ - + diff --git a/spring-framework-reference/src/cache.xml b/spring-framework-reference/src/cache.xml index fc56f186e56..f44fd43cf53 100644 --- a/spring-framework-reference/src/cache.xml +++ b/spring-framework-reference/src/cache.xml @@ -219,6 +219,18 @@ public Book findBook(String name)]]> + +
+ <literal>@CachePut</literal> annotation + + For cases where the cache needs to be updated without interferring with the method execution, one can use the @CachePut annotation. That is, the method will always + be executed and its result placed into the cache (according to the @CachePut options). It supports the same options as @Cacheable and should be used + for cache population rather then method flow optimization. + + Note that using @CachePut and @Cacheable annotations on the same method is generaly discouraged because they have different behaviours. While the latter + causes the method execution to be skipped by using the cache, the former forces the execution in order to execute a cache update. This leads to unexpected behaviour and with the exception of specific + corner-cases (such as annotations having conditions that exclude them from each other), such declarations should be avoided. +
<literal>@CacheEvict</literal> annotation @@ -240,6 +252,18 @@ public void loadBooks(InputStream batch)]]> the cache) - this is not the case with @Cacheable which adds/update data into the cache and thus requires a result.
+
+ <literal>@Caching</literal> annotation + + There are cases when multiple annotations of the same type, such as @CacheEvict or @CachePut need to be specified, for example because the condition or the key + expression is different between different caches. Unfortunately Java does not support such declarations however there is a workaround - using a enclosing annotation, in this case, + @Caching. @Caching allows multiple nested @Cacheable, @CachePut and @CacheEvict to be used on the same method: + + + +
+
Enable caching annotations @@ -352,10 +376,10 @@ public void loadBooks(InputStream batch)]]> Method visibility and - <interfacename>@Cacheable/@CacheEvcit</interfacename> + @Cacheable/@CachePut/@CacheEvict When using proxies, you should apply the - @Cacheable/@CacheEvict annotations only to + @Cache* annotations only to methods with public visibility. If you do annotate protected, private or package-visible methods with these annotations, no error is raised, but the annotated method does not exhibit the configured @@ -366,9 +390,9 @@ public void loadBooks(InputStream batch)]]> Spring recommends that you only annotate concrete classes (and methods of concrete classes) with the - @Cacheable/@CacheEvict annotation, as opposed + @Cache* annotation, as opposed to annotating interfaces. You certainly can place the - @Cacheable/@CacheEvict annotation on an + @Cache* annotation on an interface (or an interface method), but this works only as you would expect it to if you are using interface-based proxies. The fact that Java annotations are not inherited from interfaces @@ -434,10 +458,10 @@ public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)]]>< - + - +