`
mindfocus
  • 浏览: 17027 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

Memcached入门

阅读更多
Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

一)Memcached服务器
http://www.splinedancer.com/memcached-win32/下载安装文件并解压到c:\memcached;在Windows命令行控制台(cmd)界面上,进入cd c:\memcached目录下。可执行以下操作:
# 安装
memcached -d install
# 启动
memcached -d start
# 停止
memcached -d stop


二)Memcached客户端
https://github.com/gwhalin/Memcached-Java-Client/tree/master/src下载Jar包(选择Download),添加Jar到项目中。可写如下的简单测试程序:
import com.danga.MemCached.MemCachedClient;
import com.danga.MemCached.SockIOPool;

public class BasicTest {
	protected static MemCachedClient mcc  = new MemCachedClient();
	static {	
		String[] servers = { "127.0.0.1:11211" };		
		Integer[] weights = { 3 };
		SockIOPool pool = SockIOPool.getInstance();	
		pool.setServers(servers);
		pool.setWeights(weights);
		pool.setInitConn(5);
		pool.setMinConn(5);
		pool.setMaxConn(250);
		pool.setMaxIdle(1000 * 60 * 60 * 6);	
		pool.setMaintSleep(30);
		pool.setNagle(false);
		pool.setSocketTO(3000);
		pool.setSocketConnectTO(0);
		pool.initialize();
	}

	public static void main(String[] args) throws Exception {
		mcc.set("foo", "Hello, world!");
		Object bar = mcc.get("foo");
		System.out.println(bar);	
	}
}



三)Memcached更多的资料
Memcached在Google上的网址:http://code.google.com/p/memcached/
Memcached的官方网址:http://memcached.org/
上面的服务器是搭建在Windows平台上,客户端使用的是Memcached-Java-Client提供的Jar包。其他平台、语言(各种语言有多个实现库)的Memcached实现及其详细的使用方法,在上面两个网址中可以找到丰富的参考资料(比如Wiki, FAQ等)。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics