跳至主要内容

博文

目前显示的是 2015的博文

Spring JCache support

Spring JCache support Spring 4 provides seamless JCache integration. Enable Caching In this example, use EhCache as JCache specification provider. 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 aCacheManagerprovider in your configuration. @Override @Bean public CacheManager cacheManager() { JCacheCacheManager cacheManager = new JCacheCacheManager(); cacheManager.setCacheManager(new JCacheManager( new JCacheCachingProvider(), ehcache(), null, null)); return cacheManager; } private net.sf.ehcache.CacheManager ehcache() { return new net.sf.ehcache.CacheManager(); } @Override @Bean public KeyGenerator keyGenerator() { return new SimpleKeyGenerator(); } Do not forget to add theehcache-core,jcache,cache-apidependencies in your Maven pom.xml file. <dependency> <groupId>net.sf.ehcache</groupI…

Caching with Infinispan(Remote standalone server)

Spring Caching with Infinispan(Remote standalone server) Infinispan Spring Integration providesSpringRemoteCacheManagerto connect remote infinispan server. Get JBoss Infinispan Download a copy ofJBoss 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 aCacheManagerprovider in your configuration. There is aSpringRemoteCacheManagerprovided by Infinispan Spring integration.

Caching with Infinispan

Spring Caching with Infinispan JBoss Infinispan is popular distributed caching solution, it is the base of RedHad Data Grid product. In the real world projects, Infinispan can work in several ways. Run as a standalone server.Run as JBoss service.Embedded. Infinispan also provides Spring integration, and provides two differentCacheManagerimplementations for embedded way and standalone servers. This post focus on the embedded way, the next post will contain the standalone environment configuration. 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 aCacheManagerprovider in your configuration. There is a

Caching with HazelCast

Spring Caching with HazelCastHazelCastis a popular distributed caching solution, it provides Spring integration and also provides aCacheManagerimplementation. Get HazelCast HazelCast provides commercial and open source version, download an open source copy from thecommunity HazelCast website. Unzip it into your local system. And run it. 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 aCacheManagerprovider in your configuration. @Override @Bean public CacheManager cacheManager() { return new HazelcastCacheManager(hazelcastInstance()); } @Bean public HazelcastInstance hazelcastInstance()

Caching with JCache

Spring Caching with JCache JCache is a Java EE specification which missed the Java EE 7 train, but it is ready for Java EE 8 now. EhCache, Infinispan etc provide implementations of JCache 1.0 specification. Spring core provides a bridge between JCache and Spring Caching abstraction. 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 aCacheManagerprovider in your configuration. There is aJCacheCacheManagerprovided by Spring. But also specify JCache will use EhCache as backend implementation. @Override @Bean public CacheManager cacheManager() { JCacheCacheManager cacheManager = new JCacheCacheManager(); cacheManager.setCacheManager(new JCacheManager( new JCacheCachingProvider(), ehcache(), null, null)); return cacheManager; } private net.sf.ehcache.CacheManager ehcache() { return new net.sf.ehc…

Caching with Redis

Spring Caching with RedisSpring Data Redisproject provide an CacheManager implementation for Redis. Get Redis Get a copy of Redis fromofficial Redis website. In most of linux distribution, you can install it from distribution repository directly. Before you run you codes, 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, configure a Redis specificCacheManager. @Override @Bean public CacheManager cacheManager() { RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate()); return cacheManager; } @Bean public RedisTemplate redisTemplate() { RedisTemplate redisTemplate = new RedisTemplate(); redisTemplate.setConnectionFactory(jedisConnectionFactory()); return redisTemplate; } @Bean public JedisConnectionFactory jedisConnectionFactory() { // JedisPoolConfig poolCon…

Caching with GemFire

Spring Caching with Pivotal GemFireSpring Data Gemfireproject provides a CacheManager implementation forPivotal Gemfire. Get Gemfire First you have to get a trial copy fromPivotal Gemfire. Install it into your system, and make sure it runing. 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 aCacheManagerprovider in your configuration. There is aGuavaCacheManagerprovided by Spring.