zoukankan      html  css  js  c++  java
  • spring-boot + Ehcache without XML

    http://stackoverflow.com/questions/21944202/using-ehcache-in-spring-4-without-xml

    1、Ehcache配置类

    @Configuration
    @EnableCaching
    public class CachingConfig implements CachingConfigurer {
        @Bean(destroyMethod="shutdown")
        public net.sf.ehcache.CacheManager ehCacheManager() {
            CacheConfiguration cacheConfiguration = new CacheConfiguration();
            cacheConfiguration.setName("myCacheName");
            cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
            cacheConfiguration.setMaxEntriesLocalHeap(1000);
    
            net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
            config.addCache(cacheConfiguration);
    
            return net.sf.ehcache.CacheManager.newInstance(config);
        }
    
        @Bean
        @Override
        public CacheManager cacheManager() {
            return new EhCacheCacheManager(ehCacheManager());
        }
    
        @Bean
        @Override
        public KeyGenerator keyGenerator() {
            return new SimpleKeyGenerator();
        }
    }

    2、调试简单配置类

    @Configuration
    @EnableCaching
    public class CachingConfig implements CachingConfigurer {
        @Bean
        @Override
        public CacheManager cacheManager() {
            SimpleCacheManager cacheManager = new SimpleCacheManager();
    
            List<Cache> caches = new ArrayList<Cache>();
            caches.add(new ConcurrentMapCache("myCacheName"));
            cacheManager.setCaches(caches);
    
            return cacheManager;
        }
    
        @Bean
        @Override
        public KeyGenerator keyGenerator() {
            return new SimpleKeyGenerator();
        }
    }
  • 相关阅读:
    一起学Windows phone 7开发(四. DeepZoom)
    设计模式Observer(观察者模式)
    今天挺开心
    设计模式Singleton(单例模式)
    PointFromScreen和PointFromScreen的用法和区别
    设计模式Adapter(适配器模式)
    设计模式Abstract Factory(抽象工厂)
    C++多线程信号量,互斥
    linux bash 几个命令
    大小端存储
  • 原文地址:https://www.cnblogs.com/feika/p/4431599.html
Copyright © 2011-2022 走看看