oscachepool.java

来自「羽量级数据持久层开发框架」· Java 代码 · 共 63 行

JAVA
63
字号
package org.speedframework.cache;

import org.speedframework.exception.SpeedFrameworkException;
import com.opensymphony.oscache.base.NeedsRefreshException;
import com.opensymphony.oscache.general.GeneralCacheAdministrator;

/**
 * 
 * @author victorching
 * 
 */
public class OSCachePool implements CachePool {

	/**
	 * 
	 */


	private static GeneralCacheAdministrator cache = null;

	public OSCachePool(String region) {
		if (cache == null) {
			cache = new GeneralCacheAdministrator();
		}
	}

	// public void newInstance(String region) throws CacheException {
	// key = region;
	// if (!cachePool.containsKey(region)) {
	// GeneralCacheAdministrator cache = new GeneralCacheAdministrator();
	// cachePool.put(region, cache);
	// }
	//
	// }

	public synchronized void put(Object name, Object value) throws SpeedFrameworkException {
		cache.putInCache(name.toString(), value);
	}

	public synchronized Object get(Object name) {
		Object obj = null;
		try {
			obj = cache.getFromCache(name.toString());
		} catch (NeedsRefreshException e) {
			cache.cancelUpdate(name.toString());
		}
		return obj;
	}

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

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

	public synchronized void remove(Object name) throws SpeedFrameworkException {
		cache.removeEntry(name.toString());
	}

}

⌨️ 快捷键说明

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