diff --git a/spring-framework-reference/src/cache.xml b/spring-framework-reference/src/cache.xml
index 7b4744b94ee..b3fe6b42ab8 100644
--- a/spring-framework-reference/src/cache.xml
+++ b/spring-framework-reference/src/cache.xml
@@ -124,15 +124,15 @@ public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed]]>
-@Cacheable(value="book", key="#isbn"
+@Cacheable(value="books", key="#isbn"
public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)
-@Cacheable(value="book", key="#isbn.rawNumber")
+@Cacheable(value="books", key="#isbn.rawNumber")
public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)
-@Cacheable(value="book", key="T(someType).hash(#isbn)")
+@Cacheable(value="books", key="T(someType).hash(#isbn)")
public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)The snippets above, show how easy it is to select a certain argument, one of its properties or even an arbitrary (static) method.
@@ -350,6 +350,45 @@ public void loadBooks(InputStream batch)]]>
linkend="mvc-servlet" /> for more information.
+
+ Method visibility and
+ @Cacheable/@CacheEvcit
+
+ When using proxies, you should apply the
+ @Cacheable/@CacheEvict 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
+ caching settings. Consider the use of AspectJ (see below) if you
+ need to annotate non-public methods as it changes the bytecode itself.
+
+
+
+ Spring recommends that you only annotate concrete classes (and
+ methods of concrete classes) with the
+ @Cacheable/@CacheEvict annotation, as opposed
+ to annotating interfaces. You certainly can place the
+ @Cacheable/@CacheEvict 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
+ means that if you are using class-based proxies
+ (proxy-target-class="true") or the weaving-based
+ aspect (mode="aspectj"), then the caching
+ settings are not recognized by the proxying and weaving
+ infrastructure, and the object will not be wrapped in a
+ caching proxy, which would be decidedly
+ bad.
+
+
+
+ In proxy mode (which is the default), only external method calls
+ coming in through the proxy are intercepted. This means that
+ self-invocation, in effect, a method within the target object calling
+ another method of the target object, will not lead to an actual
+ caching at runtime even if the invoked method is marked with
+ @Cacheable - considering using the aspectj mode in this case.
+
@@ -383,6 +422,47 @@ public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)]]><
+
+ Declarative XML-based caching
+
+ If annotations are not an option (no access to the sources or no external code), one can use XML for declarative caching. So instead of annotating the methods for caching, one specifies
+ the target method and the caching directives externally (similar to the declarative transaction management advice). The previous example
+ can be translated into:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ...
+ // cache manager definition omitted
+ ]]>
+
+
+ In the configuration above, the bookService is made cacheable. The caching semantics to apply are encapsulated in the cache:advice definition which
+ instructs method findBooks to be used for putting data into the cache while method loadBooks for evicting data. Both definitions are working against the
+ books cache.
+
+ The aop:config definition applies the cache advice to the appropriate points in the program by using the AspectJ pointcut expression (more information is available
+ in ). In the example above, all methods from the BookService are considered and the cache advice applied to them.
+
+ The declarative XML caching supports all of the annotation-based model so moving between the two should be fairly easy - further more both can be used inside the same application.
+ The XML based approach does not touch the target code however it is inherently more verbose; when dealing with classes with overloaded methods that are targeted for caching, identifying the
+ proper methods does take an extra effort since the method argument is not a good discriminator - in these cases, the AspectJ pointcut can be used to cherry pick the target
+ methods and apply the appropriate caching functionality. Howeve through XML, it is easier to apply a package/group/interface-wide caching (again due to the AspectJ poincut) and to create
+ template-like definitions (as we did in the example above by defining the target cache through the cache:definitions cache attribute).
+
+ Configuring the cache storage
@@ -450,7 +530,6 @@ public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)]]><
or gemfireCache (configured above) will be handled by the no op cache, which will not store any information causing the target method to be executed every time.
-