您的位置:首页 > 其它

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

2016-10-29 14:27 246 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: