码迷,mamicode.com
首页 > 系统相关 > 详细

memcached

时间:2015-07-15 00:03:08      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

public class CacheUtils {

    private static MemCachedClient mcc = new MemCachedClient();

    private static CacheUtils utils = new CacheUtils();

    static {

        String[] servers = {"127.0.0.1:11211"};

        Integer[] weights = {3};

        SockIOPool pool = SockIOPool.getInstance();

        pool.setServers( servers );

        pool.setFailover( true );

        pool.setInitConn( 10 );

        pool.setMinConn( 5 );

        pool.setMaxConn( 250 );

        pool.setMaintSleep( 3000 );

        pool.setNagle( false );

        pool.setSocketTO( 3000 );

        pool.setAliveCheck( true );

        pool.initialize();

    }

    private CacheUtils() {    }

    public static CacheUtils getInstance() { return utils;    }

    public boolean add(String key, Object value) {

        return mcc.add(key, value);

    }

    public boolean add(String key, Object value, Date expiry) {

        return mcc.add(key, value, expiry);

    }

    public boolean replace(String key, Object value) {

        return mcc.replace(key, value);

    }

    public boolean replace(String key, Object value, Date expiry) {

        return mcc.replace(key, value, expiry);

    }

    public Object get(String key) {

        return mcc.get(key);

    }

}




memcached

标签:

原文地址:http://my.oschina.net/u/1453451/blog/478613

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!