📄 ehcachepool.java
字号:
package org.speedframework.cache;
import java.io.Serializable;
import java.util.Hashtable;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.apache.jcs.access.exception.CacheException;
/**
* ehcache pool 实现
* @author lizf
*
*/
public class EhCachePool implements Serializable, CachePool {
/**
*
*/
private static final long serialVersionUID = -2254582283006439144L;
private static Hashtable cachePool = new Hashtable();
private static String key = null;
public void newInstance(String region) throws CacheException {
Cache cache = null;
key = region;
if (!cachePool.containsKey(region)) {
CacheManager manager = CacheManager.create();
manager.addCache(region);
cache = manager.getCache(region);
cachePool.put(region, cache);
}
}
public void put(Object name, Object value) throws CacheException {
Element element = new Element(name, value);
( (Cache) cachePool.get(key)).put(element);
}
public Object get(Object name) {
Element element = ( (Cache) cachePool.get(key)).get(name);
if(element!=null){
return element.getValue();
}
return null;
}
public String getStats() {
return ( (Cache) cachePool.get(key)).getStatistics().toString();
}
public void putInGroup(Object name, Object value) throws
CacheException {
// ( (Cache) cachePool.get(key)).putSafe(name, value);
}
public void dispose() {
( (Cache) cachePool.get(key)).dispose();
cachePool.remove(key);
}
public void remove(Object name) throws CacheException {
( (Cache) cachePool.get(key)).remove(name);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -