| | |
| | | package com.yeshi.fanli.util;
|
| | |
|
| | | import net.sf.ehcache.Cache;
|
| | | import net.sf.ehcache.CacheManager;
|
| | | import net.sf.ehcache.config.CacheConfiguration;
|
| | |
|
| | | public class EhcacheUtil {
|
| | | |
| | | public static CacheManager cacheManager = CacheManager.getInstance();
|
| | | |
| | | public static Cache addCahae(CacheConfiguration cacheConfiguration){
|
| | | cacheManager.addCache(new Cache(cacheConfiguration));
|
| | | return cacheManager.getCache(cacheConfiguration.getName());
|
| | | }
|
| | | |
| | | public static void removeCache(String name){
|
| | | cacheManager.removeCache(name);
|
| | | }
|
| | | |
| | | public static Cache getCache(String name){
|
| | | return cacheManager.getCache(name);
|
| | | }
|
| | | |
| | | public static CacheConfiguration getMyPubCacheConfig(String name){
|
| | | CacheConfiguration cacheConfiguration = new CacheConfiguration();
|
| | | cacheConfiguration.setMaxElementsInMemory(1000);
|
| | | cacheConfiguration.setMaxElementsOnDisk(10000);
|
| | | cacheConfiguration.setEternal(false);
|
| | | cacheConfiguration.setTimeToIdleSeconds(Constant.DAYMS);
|
| | | cacheConfiguration.setTimeToLiveSeconds(Constant.DAYMS);
|
| | | cacheConfiguration.setOverflowToDisk(true);
|
| | | cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
|
| | | cacheConfiguration.setName(name);
|
| | | return cacheConfiguration;
|
| | | }
|
| | | |
| | | public static CacheConfiguration getOneDayCacheConfig(String name){
|
| | | CacheConfiguration cacheConfiguration = new CacheConfiguration();
|
| | | cacheConfiguration.setMaxElementsInMemory(1000);
|
| | | cacheConfiguration.setMaxElementsOnDisk(10000);
|
| | | cacheConfiguration.setEternal(false);
|
| | | cacheConfiguration.setTimeToLiveSeconds(86400000);
|
| | | cacheConfiguration.setOverflowToDisk(true);
|
| | | cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
|
| | | cacheConfiguration.setName(name);
|
| | | return cacheConfiguration;
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.util; |
| | | |
| | | import net.sf.ehcache.Cache; |
| | | import net.sf.ehcache.CacheManager; |
| | | import net.sf.ehcache.config.CacheConfiguration; |
| | | |
| | | public class EhcacheUtil { |
| | | |
| | | public static CacheManager cacheManager = CacheManager.getInstance(); |
| | | |
| | | public static Cache addCahae(CacheConfiguration cacheConfiguration){ |
| | | cacheManager.addCache(new Cache(cacheConfiguration)); |
| | | return cacheManager.getCache(cacheConfiguration.getName()); |
| | | } |
| | | |
| | | public static void removeCache(String name){ |
| | | cacheManager.removeCache(name); |
| | | } |
| | | |
| | | public static Cache getCache(String name){ |
| | | return cacheManager.getCache(name); |
| | | } |
| | | |
| | | public static CacheConfiguration getMyPubCacheConfig(String name){ |
| | | CacheConfiguration cacheConfiguration = new CacheConfiguration(); |
| | | cacheConfiguration.setMaxElementsInMemory(1000); |
| | | cacheConfiguration.setMaxElementsOnDisk(10000); |
| | | cacheConfiguration.setEternal(false); |
| | | cacheConfiguration.setTimeToIdleSeconds(Constant.DAYMS); |
| | | cacheConfiguration.setTimeToLiveSeconds(Constant.DAYMS); |
| | | cacheConfiguration.setOverflowToDisk(true); |
| | | cacheConfiguration.setMemoryStoreEvictionPolicy("LRU"); |
| | | cacheConfiguration.setName(name); |
| | | return cacheConfiguration; |
| | | } |
| | | |
| | | public static CacheConfiguration getOneDayCacheConfig(String name){ |
| | | CacheConfiguration cacheConfiguration = new CacheConfiguration(); |
| | | cacheConfiguration.setMaxElementsInMemory(1000); |
| | | cacheConfiguration.setMaxElementsOnDisk(10000); |
| | | cacheConfiguration.setEternal(false); |
| | | cacheConfiguration.setTimeToLiveSeconds(86400000); |
| | | cacheConfiguration.setOverflowToDisk(true); |
| | | cacheConfiguration.setMemoryStoreEvictionPolicy("LRU"); |
| | | cacheConfiguration.setName(name); |
| | | return cacheConfiguration; |
| | | } |
| | | } |