org.infinispan.spring.provider.package-info Maven / Gradle / Ivy
/**
* Spring Infinispan - An implementation of Spring 3.2's Cache SPI based on JBoss Infinispan.
*
* Spring 3.1 introduces caching capabilities a user may comfortably utilize via a set of custom annotations, thus telling
* the Spring runtime which objects to cache under which circumstances.
* Out of the box, Spring ships with EHCache as the caching provider to delegate to. It defines, however, a
* simple SPI vendors may implement for their own caching solution, thus enabling Spring users to swap out the default
* EHCache for another cache of their choosing. This SPI comprises two interfaces:
*
* -
* {@link org.springframework.cache.Cache
Cache
}, Spring's cache abstraction itself, and
*
* -
* {@link org.springframework.cache.CacheManager
CacheManager
}, a service for creating Cache
* instances
*
*
* Spring Infinispan implements this SPI for JBoss Infinispan.
*
*
* While Spring Infinispan offers only one implementation of org.springframework.cache.Cache
, namely
* {@link org.infinispan.spring.provider.SpringCache org.infinispan.spring.provider.SpringCache
}, there are two implementations
* of org.springframework.cache.CacheManager
:
*
* -
* {@link org.infinispan.spring.provider.SpringEmbeddedCacheManager
org.infinispan.spring.provider.SpringEmbeddedCacheManager
}
* and
*
* -
* {@link org.infinispan.spring.provider.SpringRemoteCacheManager
org.infinispan.spring.provider.SpringRemoteCacheManager
}.
*
*
* These two implementations cover two distinct use cases:
*
* -
* Embedded: Embed your Spring-powered application into the same JVM running an Infinispan node, i.e. every
* communication between application code and Infinispan is in-process. Infinispan supports this use case via the interface
* {@link org.infinispan.manager.EmbeddedCacheManager
org.infinispan.manager.EmbeddedCacheManager
} and its default
* implementation {@link org.infinispan.manager.DefaultCacheManager org.infinispan.manager.DefaultCacheManager
}. The
* latter backs {@link org.infinispan.spring.provider.SpringEmbeddedCacheManager SpringEmbeddedCacheManager
}.
*
* -
* Remote: Application code accesses Infinispan nodes remotely using Infinispan's own hotrod
* protocol. Infinispan supports this use case via {@link org.infinispan.client.hotrod.RemoteCacheManager
*
org.infinispan.client.hotrod.RemoteCacheManager
}. {@link org.infinispan.spring.provider.SpringRemoteCacheManager
* SpringRemoteCacheManager
} delegates to it.
*
*
*
* Usage
*
* Using Spring Infinispan as a Spring Cache provider may be divided into two broad areas:
*
* -
* Telling the Spring runtime to use Spring Infinispan and therefore Infinispan as its caching provider.
*
* -
* Using Spring's caching annotations in you application code.
*
*
*
*
* Register Spring Infinispan with the Spring runtime
*
* Suppose we want to use Spring Infinispan running in embedded mode as our caching provider, and suppose further that
* we want to create two named cache instances, "cars" and "planes". To that end, we put
*
* <beans xmlns="http://www.springframework.org/schema/beans"
* xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
* xmlns:cache="http://www.springframework.org/schema/cache"
* xmlns:p="http://www.springframework.org/schema/p"
* xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
* http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
* <cache:annotation-driven />
*
* <bean id="cacheManager" class="org.infinispan.spring.SpringEmbeddedCacheManagerFactoryBean"
* p:configuration-file-location="classpath:/org/infinispan/spring/embedded/example/infinispan-sample-config.xml"/>
*
* </beans>
*
* in our Spring application context. It is important to note that classpath:/org/infinispan/spring/embedded/example/infinispan-sample-config.xml
* points to a configuration file in the standard Infinispan configuration format that includes sections for two named caches
* "cars" and "planes". If those sections are missing the above application context will still work, yet the
* two caches "cars" and "planes" will be configured using the default settings defined in
* classpath:/org/infinispan/spring/embedded/example/infinispan-sample-config.xml
.
* To further simplify our setup we may omit the reference to an Infinispan configuration file in which case the underlying
* {@link org.infinispan.manager.EmbeddedCacheManager org.infinispan.manager.EmbeddedCacheManager
} will use Infinispan's
* default settings.
*
*
* For more advanced ways to configure the underlying Infinispan EmbeddedCacheManager
see
* {@link org.infinispan.spring.provider.SpringEmbeddedCacheManagerFactoryBean org.infinispan.spring.provider.SpringEmbeddedCacheManagerFactoryBean
}.
*
*
* If running Infinispan in remote mode the above configuration changes to
*
* <beans xmlns="http://www.springframework.org/schema/beans"
* xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
* xmlns:cache="http://www.springframework.org/schema/cache"
* xmlns:p="http://www.springframework.org/schema/p"
* xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
* http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
* <cache:annotation-driven />
*
* <bean id="cacheManager" class="org.infinispan.spring.SpringEmbeddedCacheManagerFactoryBean"
* p:configuration-properties-file-location="classpath:/org/infinispan/spring/remote/example/hotrod-client-sample.properties"/>
*
* </beans>
*
*
*
* For more advanced ways to configure the underlying Infinispan RemoteCacheManager
see
* {@link org.infinispan.spring.provider.SpringRemoteCacheManagerFactoryBean org.infinispan.spring.provider.SpringRemoteCacheManagerFactoryBean
}.
*
* Using Spring's caching annotations in application code
*
* A detailed discussion about how to use Spring's caching annotations {@link org.springframework.cache.annotation.Cacheable @Cacheable
}
* and {@link org.springframework.cache.annotation.CacheEvict @CacheEvict
} is beyond this documentation's scope. A simple example may
* serve as a starting point:
*
* import org.springframework.cache.annotation.CacheEvict;
* import org.springframework.cache.annotation.Cacheable;
* import org.springframework.stereotype.Repository;
*
* @Repository
* public class CarRepository {
*
* @Cacheable("cars")
* public Car getCar(Long carId){
* ...
* }
*
* @CacheEvict(value="cars", key="car.id")
* public void saveCar(Car car){
* ...
* }
* }
*
* In both @Cache("cars")
and @CacheEvict(value="cars", key="car.id")
"cars" refers to the name of the cache to either
* store the returned Car
instance in or to evict the saved/updated Car
instance from. For a more detailed explanation of
* how to use @Cacheable
and @CacheEvict
see the relevant reference documentation
* chapter.
*
*/
package org.infinispan.spring.provider;