/src/com/jieshuhuiyou/util/memcachedHelper.java
Java | 110 lines | 54 code | 22 blank | 34 comment | 0 complexity | c0dc7277694f759b6b6c5c746edab18e MD5 | raw file
- package com.jieshuhuiyou.util;
- import java.util.Date;
- import com.alibaba.fastjson.annotation.JSONType;
- import com.danga.MemCached.MemCachedClient;
- import com.danga.MemCached.SockIOPool;
- /**
- * memcahed???
- * @author Michael
- *
- */
- public class memcachedHelper {
- // ?????????
- protected static MemCachedClient mcc = new MemCachedClient();
-
- protected static memcachedHelper memCached = new memcachedHelper();
-
- // ????????????
- static {
- // ?????????
- String[] servers = {"127.0.0.1:11211"};
- Integer[] weights = {3};
- // ??socke????????
- 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 );
- // ??TCP?????????
- pool.setNagle( false );
- pool.setSocketTO( 3000 );
- pool.setSocketConnectTO( 0 );
- // ??????
- pool.initialize();
- // ???????????????K?????????
- mcc.setCompressEnable( true );
- mcc.setCompressThreshold( 64 * 1024 );
- }
-
- /**
- * ???????????????
- *
- */
- protected memcachedHelper()
- {
-
- }
-
- /**
- * ??????.
- * @return
- */
- public static memcachedHelper getInstance()
- {
- return memCached;
- }
-
- /**
- * ????????????.
- * @param key
- * @param value
- * @return
- */
- public boolean add(String key, Object value)
- {
- return mcc.add(key, value);
- }
-
- public boolean add(String key, Object value, Date expiry)
- {
- return mcc.add(key, value, expiry);
- }
-
- public boolean replace(String key, Object value)
- {
- return mcc.replace(key, value);
- }
-
- public boolean replace(String key, Object value, Date expiry)
- {
- return mcc.replace(key, value, expiry);
- }
-
- /**
- * ????????????.
- * @param key
- * @return
- */
- public Object get(String key)
- {
- return mcc.get(key);
- }
- }