基于HashMap实现简单的缓存处理


	private static Map<String, Object> cacheMap;
	
	public static Object getCache(String key, Object defaultValue) {
		Object obj = getCacheMap().get(key);
		//Object obj = getSession().getAttribute(key);
		return obj==null?defaultValue:obj;
	}

	public static void putCache(String key, Object value) {
		getCacheMap().put(key, value);
		//getSession().setAttribute(key, value);
	}

	public static void removeCache(String key) {
		getCacheMap().remove(key);
		//getSession().removeAttribute(key);
	}
	
	
	public static Map<String, Object> getCacheMap() {
		if (cacheMap==null){
			cacheMap = new HashMap<String, Object>();
		}
		return cacheMap;
	}



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM