ehcache操作

public class DisposeCache
{
   
    private CacheManager singletonManager;
   
    private String EHCACHE_NAME = "COM.HUAWEI.TBSC";
   
    /**
     * create CacheManager
     */
    public DisposeCache() throws CacheException
    {
        if (null == singletonManager)
        {
            singletonManager = CacheManager.getInstance();
        }
    }
   
    /**
     * add Cache to CacheManager
     */
    public void addCache(String name) throws IllegalStateException, ObjectExistsException, CacheException
    {
        singletonManager.addCache(name);
    }
   
    /**
     * remove Cache from CacheManager
     */
    public void removeCache(String name) throws IllegalStateException
    {
        singletonManager.removeCache(name);
    }
   
    /**
     * shutdown CacheManager
     */
    public void shutdown()
    {
        singletonManager.shutdown();
    }
   
    /**
     * getCache from CacheManager
     */
    public Cache getCache() throws IllegalStateException, ClassCastException
    {
        return singletonManager.getCache(EHCACHE_NAME);    
    }
   
    /**
     * create element to cache
     */
    public void create(String key, Object value) throws IllegalArgumentException, IllegalStateException, CacheException
    {
        Element element = new Element(key, value);
        getCache().put(element); 
    }
   
    /**
     * getValue form cache
     */
    public Object getValue(String key) throws IllegalStateException, CacheException
    {
        Element element = getCache().get(key);
        return element.getObjectValue();
    }
   
    /**
     * remove cache
     */
    public void remove(String key) throws IllegalStateException
    {
        getCache().remove(key);  
    }
   
}

你可能感兴趣的:(cache)