码迷,mamicode.com
首页 > 其他好文 > 详细

工作中遇到的问题--缓存配置(使用@Configuration装配 @Bean的方式注入)

时间:2015-11-20 17:01:27      阅读:2276      评论:0      收藏:0      [点我收藏+]

标签:

@EnableCaching
@Configuration
public class MFGCachingConfiguration {

@Autowired
private MFGSettings mfgSettings;

@Bean(name="MFGKeyGenerator")
public KeyGenerator MFGKeyGenerator(){
SimpleKeyGenerator defaultKeyGen = new SimpleKeyGenerator();
KeyGenerator mfgKeyGen = new KeyGenerator(){

@Override
public Object generate(Object target, Method method, Object... params) {
if(method != null){
return method.getName() + defaultKeyGen.generate(target, method, params);
} else {
return defaultKeyGen.generate(target, method, params);
}
}

};
return mfgKeyGen;
}


@Bean
public CacheManager getEhCacheManager() {
CacheConfiguration ehCacheConf = new CacheConfiguration();
ehCacheConf.setName("dashboard_cache");
ehCacheConf.setMaxEntriesLocalDisk(1000l);
ehCacheConf.setMaxEntriesLocalHeap(5000l);
ehCacheConf.setEternal(false);
ehCacheConf.setDiskSpoolBufferSizeMB(50);
int dashboardCacheCleanUpSchedulerFrequency = Integer.parseInt(mfgSettings.getDashboardCacheCleanUpSchedulerFrequency());
ehCacheConf.setTimeToIdleSeconds(dashboardCacheCleanUpSchedulerFrequency);
ehCacheConf.setTimeToLiveSeconds(dashboardCacheCleanUpSchedulerFrequency);
ehCacheConf.setMemoryStoreEvictionPolicy("LFU");
ehCacheConf.setTransactionalMode("OFF");
ehCacheConf.addPersistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP));

net.sf.ehcache.config.Configuration configration = new net.sf.ehcache.config.Configuration();
configration.setName("dashboard_cache");
configration.addCache(ehCacheConf);

CacheManager cacheManager = new EhCacheCacheManager(new net.sf.ehcache.CacheManager(configration));
return cacheManager;
}
}

工作中遇到的问题--缓存配置(使用@Configuration装配 @Bean的方式注入)

标签:

原文地址:http://www.cnblogs.com/ly-radiata/p/4981222.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!