This document is DEPRECATED.

Please consider any information here as out of date. DO NOT use this document.

Instead, refer to

Please update your bookmarks accordingly.

Skip to end of metadata
Go to start of metadata

somewhere in your application context. This will tell Spring to be on the lookout for {font:monospace}@Cacheable{font} and {font:monospace}@CacheEvict{font} within your application code.Now, assuming you've already {font:monospace}infinispan.jar{font} and its dependencies on your classpath, all that's left to do is installing {font:monospace}infinispan-spring{font} and {font:monospace}spring{font}. For maven users this translates into

{font:monospace}Gradle{font} users will most likely know how to adapt this to their needs. Those leaning towards a more ... pedestrian way of managing their dependencies will need to download {font:monospace}Spring 3.1.0 M1{font} and install it manually alongside {font:monospace}infinispan-spring.jar{font} from the Infinispan distribution.h1. Telling Spring to use Infinispan as its caching providerSpring 3.1's cache provider SPI comprises two interfaces, {font:monospace}org.springframework.cache.CacheManager{font} and {font:monospace}org.springframework.cache.Cache{font} where a {font:monospace}CacheManager{font} serves as a factory for named {font:monospace}Cache{font} instances. By default Spring will look at runtime for a {font:monospace}CacheManager{font} implementation having the bean name "cacheManager" in an application's application context. So by putting

somewhere in your application context you tell Spring to henceforth use Infinispan as its caching provider.h1. Adding caching to your application codeAs outlined above enabling caching in your application code is as simple as adding {font:monospace}@Cacheable{font} and {font:monospace}@CacheEvict{font} to select methods. Suppose you've got a DAO for, say, books and you want book instances to be cached once they've been loaded from the underlying database using {font:monospace}BookDao#findBook(Integer bookId){font}. To that end you annotate {font:monospace}findBook(Integer bookId){font} with {font:monospace}@Cacheable{font}, as in

This will tell Spring to cache Book instances returned from calls to {font:monospace}findBook(Integer bookId){font} in a named cache "books", using the parameter's "bookId" value as a cache key. Here, "#bookId" is an expression in the [Spring Expression Language|] that evaluates to the {font:monospace}bookId{font} argument. If you don't specify the {font:monospace}key{font} attribute Spring will generate a hash from the supplied method arguments - in this case only {font:monospace}bookId{font} - and use that as a cache key. Essentially, you relinquish control over what cache key to use to Spring. Which may or may not be fine depending on your application's needs.Though the notion of actually deleting a book will undoubtedly seem alien and outright abhorrent to any sane reader there might come the time when your application needs to do just that. For whatever reason. In this case you will want for such a book to be removed not only from the underlying database but from the cache, too. So you annotate {font:monospace}deleteBook(Integer bookId){font} with {font:monospace}@CacheEvict{font} as in

and you may rest assured that no stray books be left in your application once you decide to remove them.h1. OutroHopefully you enjoyed our quick tour of Infinispan's support for Spring's cache abstraction and saw how easy it is for all your caching woes to be taken care of by Infinispan. More information may be found in Spring's as usual rather excellent [reference documentation|] and [javadocs|]. Also see [this|] very nice posting on the official Spring blog for a somewhat more comprehensive introduction to Spring's cache abstraction.{code}

cache cache Delete
spring spring Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.