⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ehcachepool.java

📁 羽量级数据持久层开发框架
💻 JAVA
字号:
package org.speedframework.cache;



import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheException;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.speedframework.exception.SpeedFrameworkException;

/**
 * ehcache pool implementation
 * 
 * @author lizf
 * 
 */
public class EhCachePool implements CachePool {

	/**
	 * 
	 */

	private static Cache cache = null;

	public EhCachePool(String region) {
		try {
			if (cache == null) {
				CacheManager manager = CacheManager.create();
				manager.addCache(region);
				cache = manager.getCache(region);
			}
		} catch (CacheException e) {
			throw new SpeedFrameworkException(
					"EhCachePool newInstance error. ", e);
		}
	}

	public synchronized void put(Object name, Object value) throws CacheException {
		Element element = new Element(name, value);
		cache.put(element);
	}

	public synchronized Object get(Object name) {
		Element element = cache.get(name);
		if (element != null) {
			return element.getValue();
		}
		return null;
	}

	public String getStats() {
		return cache.getStatistics().toString();
	}


	public void dispose() {
		cache.dispose();
	}

	public synchronized void remove(Object name) throws CacheException {
		cache.remove(name);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -