基於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