添加集合:
Map province4city4countMap=new HashMap()集合
MemCached.getInstance().set(“province4city4countMap”, province4city4countMap);
public class MemCached {
private static MemCachedClient mcc = CachedManage.getInstance().getMCC();
private volatile static MemCached memcached;
/**
* 保护型构造方法,不允许通过new实例化!
*
*/
private MemCached(){}
/**
* 获取唯一实例.
* @return
*/
public static MemCached getInstance(){
//如果memcached服务断掉,需要重新实例化对象
if(mcc.stats().isEmpty()){
synchronized(MemCached.class){
memcached=new MemCached();
}
}else if(memcached==null){
synchronized(MemCached.class){
if(memcached==null){
memcached=new MemCached();
}
}
}
return memcached;
}
/**
* 如果缓存中已经存在key,则替换原缓存中的value,否则新增一个items
* @param key
* @param value
* @return
*/
public boolean set(String key, Object value)
{
return mcc.set(key, value);
}
}