2017-11-14 8 views
0

私はすでにキャッシングソリューションのために春のキャッシング抽象化+ EhCacheインプリメンテーションを使用するシステムを持っています。しかし今、分散機能を提供する他のソリューションのためにEhCacheを切り替える必要があります。私は自分の問題に適したJCS(java Caching System)を見つけました。しかし、JCSでSpring Caching Abstractionを使用する方法を見つけることはできませんでした。 JCSでスプリングキャッシングの抽象化を使用することができるかどうかは誰にも分かりますか?もしそうなら、どうすればいいですか?バネ付きJavaキャッシングシステム

@Bean(destroyMethod = "shutdown") 
public net.sf.ehcache.CacheManager ehCacheManager() { 
    net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration(); 

    DiskStoreConfiguration store = new DiskStoreConfiguration(); 
    store.setPath(
      diskDirectory); 
    config.addDiskStore(store); 
    CacheConfiguration cacheConfiguration = new CacheConfiguration(); 
    cacheConfiguration.setName("disk"); 
    cacheConfiguration.maxEntriesLocalHeap(1); 
    cacheConfiguration.setTimeToLiveSeconds(Integer.parseInt(cacheTime)); 
    cacheConfiguration.setMemoryStoreEvictionPolicy("LRU"); 


    cacheConfiguration.maxBytesLocalDisk(Long.parseLong(diskSize), MemoryUnit.GIGABYTES); 
    PersistenceConfiguration perCache = new PersistenceConfiguration(); 
    perCache.strategy(Strategy.LOCALTEMPSWAP); 

    cacheConfiguration.addPersistence(perCache); 
    config.addCache(cacheConfiguration); 



    return net.sf.ehcache.CacheManager.newInstance(config); 
} 

私の目標は、上記のいずれかのように動作してCacheManagerのクラスを見つけることですし、そのため、anottationsなど

おかげ@cacheble、@keyとを使用することができます!

答えて

0

Infinispan?それは分散された機能を提供し、それは良いバネ統合を持っています。また、JSR 107 APIもサポートしています。

公式サイトからの抽出例:答えを

/** 
* This example shows how to configure Spring's {@link CacheManager} with 
    Infinispan implementation. 
*/ 
public class SpringAnnotationConfiguration { 

    @Configuration 
    public static class ApplicationConfiguration { 

     @Bean 
     public SpringEmbeddedCacheManagerFactoryBean springCache() { 
      return new SpringEmbeddedCacheManagerFactoryBean(); 
     } 

     @Bean 
     public CachePlayground playground() { 
      return new CachePlayground(); 
     } 
    } 

    public static class CachePlayground { 

     @Autowired 
     private CacheManager cacheManager; 

     public void add(String key, String value) { 
      cacheManager.getCache("default").put(key, value); 
     } 

     public String getContent(String key) { 
      return cacheManager.getCache("default").get(key).get().toString(); 
     } 
    } 

    public static void main(String[] args) { 
     ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ApplicationConfiguration.class); 

     CachePlayground cachePlayground = applicationContext.getBean(CachePlayground.class); 

     cachePlayground.add("Infinispan", "Is cool!"); 
     System.out.println(cachePlayground.getContent("Infinispan")); 
    } 
} 
+1

感謝。それはまさに私が必要としていたものです。 –

関連する問題