Java memcache Use of detailed

Source: Internet
Author: User


Memcached-java-client is the Memcached's official Java language Access Memcached Toolkit, which makes it easier to communicate with the cache server.
: Https://github.com/gwhalin/Memcached-Java-Client/downloads,

Download latest Version Java_memcached-release_2.6.6.zip



The Java code is as follows:

package memcache;import java.io.serializable;import java.util.date;import  Com.danga.memcached.memcachedclient;import com.danga.memcached.sockiopool;class user implements  serializable{ //object must be serialized to be saved   public String userName;  public  string password; }public class memcachemanagerforgwhalin {  //  Building a cache client      private static memcachedclient cachedclient;   //   Singleton mode for client management classes       private static MemcacheManagerForGwhalin  Instance = new memcachemanagerforgwhalin ();        private  memcachemanagerforgwhalin ()  {            Cachedclient = new memcachedclient ();            //Get Connection Pool instance    &Nbsp;        sockiopool pool = sockiopool.getinstance ()              //Set cache server address, you can set multiple implementations of distributed cache              pool.setservers (new String[]{" 127.0.0.1:11211 "});    //set initial connection 5            pool.setinitconn (5);         //Set minimum Connection 5             pool.setminconn (5);          //Setting the maximum connection 250            pool.setmaxconn          //set maximum idle time for each connection 3 hours             pool.setmaxidle (1000 * 60 * 60 * 3);       pOol.setmaintsleep (;             ) Pool.setnagle (false);            pool.setsocketto (3000);            pool.setsocketconnectto (0);         pool.initialize ();     }             /**       *     *    *  Get Cache Manager unique Instance          *   @return        */      public  Static memcachemanagerforgwhalin getinstance ()  {      return  INSTANCE;       }          public void add (string Key, object value)  {    cachedclient.set (key, value);      }         public void add (String  key, object value, int milliseconds)  {      Cachedclient.set (key, value, milliseconds);     }          public void remove (String key)  {    Cachedclient.delete (Key);       }         public void remove (string key, int milliseconds)  {       cachedclient.delete (Key, milliseconds, new date ());   }          public void update (String key, object value ,  int milliseconds)  { &NBsp;  cachedclient.replace (key, value, milliseconds);     }          public void update (String key, Object  value)  {         cachedclient.replace (Key, value) ;     }                  public object get (String key)  {          return cachedclient.get (Key);       }           public static void main (String args[ ]) {   memcachemanagerforgwhalin memcache = memcachemanagerforgwhalin.getinstance ();     memcache.add ("4",  new user ());      System.out.println (Memcache.get ("4"));      }} 

650) this.width=650; "title=" capture. PNG "alt=" wkiom1xfwnmzthcaaaeiqwedrpi981.jpg "src=" http://s3.51cto.com/wyfs02/M01/71/1C/ Wkiom1xfwnmzthcaaaeiqwedrpi981.jpg "/>


SOURCE download please see annex



Reference article:

http://asher.blog.163.com/blog/static/174174566201321421241578/


Integration with spring


http://blog.csdn.net/dhdhdh0920/article/details/42242521

This article is from the "Nothing-skywalker" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1682930

Java memcache Use of detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.