import java.util.Date;
import com.danga.MemCached.MemCachedClient;
import com.danga.MemCached.SockIOPool;
public class MemcachedCache implements ICache {
//创建全局的唯一实例
protected static MemCachedClient mcc = new MemCachedClient();
protected static MemcachedCache memCached = new MemcachedCache();
static{
//这里是magent代理服务器IP
String[] servers = {"192.168.1.160:12000"};//Integer[] weights = {3};
SockIOPool pool = SockIOPool.getInstance();
pool.setServers(servers);
//pool.setWeights(weights);
pool.setInitConn(5);
pool.setMinConn(5);
pool.setMaxConn(200);
pool.setMaxIdle(1000*30*30);
pool.setMaintSleep(30);
pool.setNagle(false);
pool.setSocketTO(30);
pool.setSocketConnectTO(0);
pool.initialize();
//mcc.setCompressEnable( true );
//mcc.setCompressThreshold( 64 * 1024 );
}
@Override
public boolean set(String key, Object value, Date date) {
return mcc.set(key, value, date);
}
@Override
public Object get(String key) {
return mcc.get(key);
}
/**
* 获取唯一实例
* @return
*/
public static MemcachedCache getInstance(){
return memCached;
}
}