memcached(java)

原创
2013/04/08 16:34
阅读数 234
package com.cached;


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


}

展开阅读全文
打赏
0
0 收藏
分享
加载中
这样去链接,希望对你有帮助。
2013/04/10 12:05
回复
举报
MemcachedClient memcacheCient = new MemcachedClient(
    new InetSocketAddress(
        Configuration.getInstance().getValue("server"),
        Integer.valueOf(Configuration.getInstance().getValue("port"))));
2013/04/10 12:05
回复
举报
http://www.cnblogs.com/mandela/archive/2011/08/05/2128529.html 这篇文章,详细介绍了下sockiopool,可以看看,能否给你帮助。
2013/04/09 09:14
回复
举报
更多评论
打赏
3 评论
0 收藏
0
分享
返回顶部
顶部