Spring Caching with Infinispan(Remote standalone server)
Infinispan Spring Integration provides
SpringRemoteCacheManager
to connect remote infinispan server.Get JBoss Infinispan
Download a copy of JBoss Infinispan.
Install it into your local system, and make sure it is running.
Enable Caching
Add
@EnableCaching(mode=AdviceMode.ASPECTJ)
annotation on the configuration class if you are using Java based configuration.@Configuration ... @EnableCaching(mode=AdviceMode.ASPECTJ) public class JpaConfig {...}
Then, specify a
CacheManager
provider in your configuration. There is a SpringRemoteCacheManager
provided by Infinispan Spring integration.@Override @Bean public CacheManager cacheManager() { return new SpringRemoteCacheManager( new RemoteCacheManager( new ConfigurationBuilder() .addServer() .host("localhost") .build() ) ); } @Override @Bean public KeyGenerator keyGenerator() { return new SimpleKeyGenerator(); }
Do not forget to add the infinispan-spring dependency in your Maven pom.xml file.
<dependency> <groupId>org.infinispan</groupId> <artifactId>infinispan-spring</artifactId> </dependency> <dependency> <groupId>org.infinispan</groupId> <artifactId>infinispan-client-hotrod</artifactId> </dependency>
Code sample
Check out the sample codes.
And explore the spring-cache-infinispan-remote folder.
评论