2017-11-14 15 views
0

캐싱 솔루션을위한 스프링 캐싱 추상화 + EhCache 구현을 사용하는 시스템이 이미 있습니다. 그러나 이제는 배포 된 기능을 제공하는 다른 솔루션으로 EhCache를 전환해야합니다. 내 문제에 적합한 JCS (java Caching System)를 찾았습니다. 그러나 스프링 캐싱 추상화를 JCS와 함께 사용하는 방법을 찾지 못했습니다. 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

감사합니다. 그게 내가 필요한거야. –