1.memcached java client一个实现的下载地址
http://www.whalin.com/memcached/#download
2. 利用memcached java client 一个简单的应用
java 代码
- package com.danga.MemCached.test;
-
- import java.util.Date;
-
- import com.danga.MemCached.MemCachedClient;
- import com.danga.MemCached.SockIOPool;
-
-
- public class Test {
- protected static MemCachedClient mcc = new MemCachedClient();
-
- static {
- String[] servers ={"192.168.40.4:12000"};
-
- 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();
-
-
-
-
- mcc.setCompressEnable( true );
- mcc.setCompressThreshold( 64 * 1024 );
- }
-
- public static void bulidCache(){
-
-
- mcc.set( "test", "This is a test String" ,new Date(10000));
-
- }
-
- public static void output() {
-
- String value = (String) mcc.get( "test" );
- System.out.println(value);
- }
-
- public static void main(String[] args){
- bulidCache();
- output();
- }
-
- }
运行输出值为:
This is a test String
3.注释掉buildCache();
十秒后运行,输出值为 null