跳至主要内容

博文

目前显示的是 三月, 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 a   CacheManager   provider 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 the   ehcache-core ,   jcache ,   cache-api   dependencies in your...

Caching with Infinispan(Remote standalone server)

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 keyGenerat...

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 different   CacheManager   implementations 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 a   CacheManager   provider in your configuration. There is a   SpringEmbeddedCacheManager   provided by Infinispan Spring integration. @Override @Bean public CacheManager cacheMana...

Caching with HazelCast

Spring Caching with HazelCast HazelCast   is a popular distributed caching solution, it provides Spring integration and also provides a   CacheManager   implementation. Get HazelCast HazelCast provides commercial and open source version, download an open source copy from the   community 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 a   CacheManager   provider in your configuration. @Override @Bean public CacheManager cacheManager() { return new HazelcastCacheManager(hazelcastInstance()); } @Bean public HazelcastInstance hazelcastInstance() { ClientNetworkConfig networkConfig = new ClientNetworkConfig() .addAddress("localhost"); ClientConfig clientConfig = new Cl...

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 a   CacheManager   provider in your configuration. There is a   JCacheCacheManager   provided 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; } priva...

Caching with Redis

Spring Caching with Redis Spring Data Redis   project provide an CacheManager implementation for Redis. Get Redis Get a copy of Redis from   official 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 specific   CacheManager . @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 JedisConnection...

Caching with GemFire

Spring Caching with Pivotal GemFire Spring Data Gemfire   project provides a CacheManager implementation for   Pivotal Gemfire . Get Gemfire First you have to get a trial copy from   Pivotal 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 a   CacheManager   provider in your configuration. There is a   GuavaCacheManager   provided by Spring. @Bean CacheFactoryBean cacheFactoryBean() { return new CacheFactoryBean(); } @Bean LocalRegionFactoryBean<String, Conference> localRegionFactory(final GemFireCache cache) { return new LocalRegionFactoryBean<String, Conference>() {{ setCache(cache); setName("conference"); }}; } @Override @Bean public CacheManag...