Import Java.util.Date; Import com.danga.MemCached.MemCachedClient; Import Com.danga.MemCached.SockIOPool; public class Memcachedutil { /** * Memcached Client Single case */ private static Memcachedclient cachedclient = new Memcachedclient (); /** * Initialize Connection Pool */ static { Get an instance of a connection pool Sockiopool pool = sockiopool.getinstance (); Server list and its weights String[] Servers = {"127.0.0.1:11211"}; Integer[] weights = {3}; Setting Up Server information Pool.setservers (servers); Pool.setweights (weights); Set number of initial connections, minimum number of connections, maximum connections, maximum processing time Pool.setinitconn (10); Pool.setminconn (10); Pool.setmaxconn (1000); Pool.setmaxidle (1000*60*60); Set the sleep time of the connection pool daemon thread Pool.setmaintsleep (60); Set TCP parameters, connection timed out Pool.setnagle (FALSE); Pool.setsocketto (60); Pool.setsocketconnectto (0); Initialize and start the connection pool Pool.initialize (); Compression settings, compressed beyond the specified size Cachedclient.setcompressenable (TRUE); Cachedclient.setcompressthreshold (1024*1024); } Private Memcachedutil () { } public static Boolean Add (String key, Object value) { Return Cachedclient.add (key, value); } public static Boolean Add (String key, Object value, Date expiredate) { Return Cachedclient.add (key, value, expiredate); } public static Boolean Add (String key, Object value, Integer millseconds) { Return Cachedclient.add (key, value, new Date (new Date (). GetTime () +millseconds)); } public static Boolean put (String key, Object value) { Return Cachedclient.set (key, value); } public static Boolean put (String key, Object value, Date expiredate) { Return Cachedclient.set (key, value, expiredate); } public static Boolean put (String key, Object value, Integer millseconds) { Return Cachedclient.set (key, value, new Date (new Date (). GetTime () +millseconds)); } public static Boolean replace (String key, Object value) { Return Cachedclient.replace (key, value); } public static Boolean replace (String key, Object value, Date expiredate) { Return Cachedclient.replace (key, value, expiredate); } public static Boolean replace (String key, Object value, Integer millseconds) { Return Cachedclient.replace (key, value, new Date (new Date (). GetTime () +millseconds)); } public static Object get (String key) { return Cachedclient.get (key); } public static Object Delete (String key) { return Cachedclient.delete (key); } } |