MemCached用法

所需要的jar包:
          com.danga.MemCached.MemCachedClient
          com.danga.MemCached.SockIOPool 自行下载
/**
* 缓存服务器集群,提供缓存连接初始化,获取缓存客户端等工作 * @author ray */ public class CacheCluster { private final static MemCachedClient client = new MemCachedClient(); private static String _memcache_config = "/WEB-INF/config/memcached.properties"; static { Properties config = FileUtil.getProperties(HttpContext.getPathPrefix() + _memcache_config); String serverGroup = config.getProperty("server"); String[] servers = serverGroup.split(";"); SockIOPool pool = SockIOPool.getInstance(); int init_conns = Integer.valueOf(config.getProperty("conn_init")); int min_spare = Integer.valueOf(config.getProperty("conn_minspare")); int max_spare = Integer.valueOf(config.getProperty("conn_maxspare")); long idel_time = Long.valueOf(config.getProperty("conn_maxideltime")); long busy_time = Long.valueOf(config.getProperty("conn_maxbusytime")); int timeout = Integer.valueOf(config.getProperty("conn_timeout")); pool.setServers(servers); pool.setInitConn(init_conns); pool.setMinConn(min_spare); pool.setMaxConn(max_spare); pool.setMaxIdle(idel_time); pool.setMaxBusyTime(busy_time); pool.setSocketTO(timeout); pool.setFailover(true); pool.initialize(); client.setCompressEnable(true); client.setCompressThreshold(64 * 1024); } public static MemCachedClient getCacheClient() { return client; } }

properties配置文件:

server=192.168.11.144:1121
conn_init=100        初始化空间大小kb
conn_minspare=100      最小分配空间kb
conn_maxspare=1000      cache空间kb
conn_maxideltime=1800000  
conn_maxbusytime=300000  最长连接数量
conn_timeout=3000      连接最长时限

 

转载于:https://www.cnblogs.com/xmaomao/p/3337514.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值