import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* 本地cache工具
*
* @author yanek
*
*/
public class LocalCache {
private static Map<String, Object> cacheMap = new ConcurrentHashMap<String, Object>();
public static void destoryCacheMap() {
cacheMap = null;
}
public static Map<String, Object> getCacheMap() {
return cacheMap;
}
public static void set(String key, Object values) {
cacheMap.put(key, values);
}
public static Object get(String key) {
return cacheMap.get(key);
}
public static String getString(String key) {
return (String) cacheMap.get(key);
}
public static Object getToEmpty(String key) {
Object o = cacheMap.get(key);
if (o == null)
return "";
else
return o;
}
public static void remove(String key) {
cacheMap.remove(key);
}
public static void clear() {
cacheMap.clear();
}
public static void main(String[] args) {
LocalCache.set("001","001");
LocalCache.set("002","002");
LocalCache.set("003","003");
System.out.println(LocalCache.get("001"));
System.out.println(LocalCache.get("002"));
System.out.println(LocalCache.get("003"));
}
}