现在的位置: 首页 > 综合 > 正文

高性能的分布式内存对象缓存系统-Memcached简介

2014年10月16日 ⁄ 综合 ⁄ 共 1181字 ⁄ 字号 评论关闭
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提供动态、数据库驱动网站的速度。Memcached基于一个存储键/值对的hashmap。其守护进程(daemon
)是用C写的,但是客户端可以用任何语言来编写,并通过memcached协议与守护进程通信。
 
JAVA客户端测试实例:
package test.memcache;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.concurrent.TimeoutException;

import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.MemcachedClientBuilder;
import net.rubyeye.xmemcached.XMemcachedClientBuilder;
import net.rubyeye.xmemcached.exception.MemcachedException;
import net.rubyeye.xmemcached.utils.AddrUtil;

public class TestMemcache {
	public static void main(String[] args) {
		List<InetSocketAddress> addrList = null;
		MemcachedClientBuilder builder = null;
		MemcachedClient memcachedClient = null;
		
		try {
			addrList = AddrUtil.getAddresses("127.0.0.1:11211");
			builder = new XMemcachedClientBuilder(addrList,new int[]{1,3});
			memcachedClient = builder.build();
			memcachedClient.add("hello", 0, " 你好!");
			System.out.print("get value : " + memcachedClient.get("hello"));
		} catch (TimeoutException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (MemcachedException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

抱歉!评论已关闭.