基于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;
	}


posted @ 2016-10-29 14:27  海的心  阅读(2314)  评论(0编辑  收藏  举报