admin
2020-05-19 744594ef1a2f530fc3e86ea9dc48b62247f79420
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
    }
}