03.gwhalin
gwhalin
  site
    https://github.com/gwhalin/Memcached-Java-Client
  howto
    https://github.com/gwhalin/Memcached-Java-Client/wiki/HOWTO
  install
    1. download 받아서 lib 안에 jar 가져다 놓으면 됩니다.
  spring 연동
    <bean id="memCachedClient"
class="com.danga.MemCached.MemCachedClient"
depends-on="sockIOPool">
<property name="compressEnable" value="true" />
<property name="compressThreshold" value="10240" />
</bean>
<bean id="sockIOPool"
class="com.danga.MemCached.SockIOPool"
factory-method="getInstance" init-method="initialize"
destroy-method="shutDown">
<property name="servers">
<list>
<value>localhost:11211</value>
</list>
</property>
<property name="weights">
<list>
<value>1</value>
</list>
</property>
<property name="initConn" value="5" />
<property name="minConn" value="5" />
<property name="maxConn" value="10" />
<property name="maxIdle" value="10800000" />
<property name="maintSleep" value="30" />
<property name="nagle" value="false" />
<property name="socketTO" value="3000" />
<property name="socketConnectTO" value="0" />
</bean>
  java sample
    import com.danga.MemCached.MemCachedClient;
import com.danga.MemCached.SockIOPool;
public class MySample {
// create a static client as most installs only need
// a single instance
protected static MemCachedClient mcc = new MemCachedClient();
// set up connection pool once at class load
static {
// server list and weights
String[] servers = { "www.mydomain.com:5701",
"www.mydomain.com:5702", "www.mydomain.com:5703" };
Integer[] weights = { 3, 3, 2 };
// grab an instance of our connection pool
SockIOPool pool = SockIOPool.getInstance();
// set the servers and the weights
pool.setServers(servers);
pool.setWeights(weights);
// set some basic pool settings
// 5 initial, 5 min, and 250 max conns
// and set the max idle time for a conn
// to 6 hours
pool.setInitConn(5);
pool.setMinConn(5);
pool.setMaxConn(250);
pool.setMaxIdle(1000 * 60 * 60 * 6);
// set the sleep for the maint thread
// it will wake up every x seconds and
// maintain the pool size
pool.setMaintSleep(30);
// set some TCP settings
// disable nagle
// set the read timeout to 3 secs
// and don’t set a connect timeout
pool.setNagle(false);
pool.setSocketTO(3000);
pool.setSocketConnectTO(0);
// initialize the connection pool
pool.initialize();
// lets set some compression on for the client
// compress anything larger than 64k
mcc.setCompressEnable(true);
mcc.setCompressThreshold(64 * 1024);
}
// from here on down, you can call any of the client calls
public static void main(String[] agrs) {
mcc.set("foo", "This is a test String");
String bar = (String) mcc.get("foo");
System.out.println("result : "+ bar);
}
}
<bean id="memCachedClient"
class="com.danga.MemCached.MemCachedClient"
depends-on="sockIOPool">
<property name="compressEnable" value="true" />
<property name="compressThreshold" value="10240" />
</bean>
<bean id="sockIOPool"
class="com.danga.MemCached.SockIOPool"
factory-method="getInstance" init-method="initialize"
destroy-method="shutDown">
<property name="servers">
<list>
<value>localhost:11211</value>
</list>
</property>
<property name="weights">
<list>
<value>1</value>
</list>
</property>
<property name="initConn" value="5" />
<property name="minConn" value="5" />
<property name="maxConn" value="10" />
<property name="maxIdle" value="10800000" />
<property name="maintSleep" value="30" />
<property name="nagle" value="false" />
<property name="socketTO" value="3000" />
<property name="socketConnectTO" value="0" />
</bean>
import com.danga.MemCached.MemCachedClient;
import com.danga.MemCached.SockIOPool;
public class MySample {
// create a static client as most installs only need
// a single instance
protected static MemCachedClient mcc = new MemCachedClient();
// set up connection pool once at class load
static {
// server list and weights
String[] servers = { "www.mydomain.com:5701",
"www.mydomain.com:5702", "www.mydomain.com:5703" };
Integer[] weights = { 3, 3, 2 };
// grab an instance of our connection pool
SockIOPool pool = SockIOPool.getInstance();
// set the servers and the weights
pool.setServers(servers);
pool.setWeights(weights);
// set some basic pool settings
// 5 initial, 5 min, and 250 max conns
// and set the max idle time for a conn
// to 6 hours
pool.setInitConn(5);
pool.setMinConn(5);
pool.setMaxConn(250);
pool.setMaxIdle(1000 * 60 * 60 * 6);
// set the sleep for the maint thread
// it will wake up every x seconds and
// maintain the pool size
pool.setMaintSleep(30);
// set some TCP settings
// disable nagle
// set the read timeout to 3 secs
// and don’t set a connect timeout
pool.setNagle(false);
pool.setSocketTO(3000);
pool.setSocketConnectTO(0);
// initialize the connection pool
pool.initialize();
// lets set some compression on for the client
// compress anything larger than 64k
mcc.setCompressEnable(true);
mcc.setCompressThreshold(64 * 1024);
}
// from here on down, you can call any of the client calls
public static void main(String[] agrs) {
mcc.set("foo", "This is a test String");
String bar = (String) mcc.get("foo");
System.out.println("result : "+ bar);
}
}