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();
        }
    }
  • 相关阅读:
    解题:POI 2008 Plot purchase
    1807. 斐波纳契数列简单
    1745. 单调数列
    1700. 增减字符串匹配
    1665. 计算数字
    1523. 分区数组
    1517. 最大子数组
    1598. 两句话中的不常见单词
    1594. 公平的糖果交换
    1510. 亲密字符串(回顾)
  • 原文地址:https://www.cnblogs.com/feika/p/4431599.html
Copyright © 2011-2022 走看看