Java + memcached Installation

Source: Internet
Author: User


One: Installation

(Temporarily get started with Windows Labs)
1. Download Memcached.exe, F:\memcached\
2. In cmd in the input "F:\memcached\memcached.exe-d install" installation.
3. Re-enter: "F:\memcached\memcached.exe-d start" starts. Later, Memcached will start as a service for Windows on its own initiative each time it is powered on.

So the server side is already installed.






Two: Java Primer package is found on the internet, the legend is Ali an expert seal
Alisoft-xplatform-asf-cache-2.5.1.jar
Hessian-3.0.1.jar
Stax-api-1.0.1.jar
Wstx-asl-2.0.2.jar




Three: Test file
Package Com.xxx.util;import Java.util.arraylist;import Java.util.date;import java.util.list;import Com.alisoft.xplatform.asf.cache.memcached.client.memcachedclient;import Com.alisoft.xplatform.asf.cache.memcached.client.sockiopool;import Com.xxx.entity.attrgrid.records;public Class        memcachedmanager{//Create Memcachedclient Global Object private static memcachedclient MCC = new Memcachedclient ();       static {//Create server list and its weight string[] servers = {"127.0.0.1:11211"};              Integer[] weights = {3};              Create a socket connection pool object Sockiopool pool = Sockiopool.getinstance ();       Set Server information pool.setservers (servers);       Pool.setweights (weights);              Pool.setfailover (TRUE);       Set the number of initial connections, minimum and maximum connections, and maximum processing time pool.setinitconn (5);       Pool.setminconn (5);       Pool.setmaxconn (250);              Pool.setmaxidle (1000*60*60*6);              Set the main thread sleep time Pool.setmaintsleep (30);       Set TCP parameters, connection timeout, etc. pool.setnagle (false); Pool.setsocketto (3000);       Pool.setsocketconnectto (0);              Pool.setalivecheck (TRUE);              Initialize the connection pool pool.initialize (); Compression settings.       Data exceeding the specified size (in K) will be compressed mcc.setcompressenable (true);    Mcc.setcompressthreshold (64 * 1024); }/** * No participation structure */protected Memcachedmanager () {} protected static Memcachedmanager Instan    CE = new Memcachedmanager ();//Singleton public static Memcachedmanager getinstance () {return instance; }/** * Joins the object into the cache.       Composition method overload * @param key * @param value * @return */public boolean Add (String Key,object value) {    Return Mcc.add (key, value);    The 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); }        /** * Gets the object according to the specified keyword */public object get (String key) {return mcc.get (key); /** * Use the Memcached object to cache the collection. and remove from cache */public static void main (string[] args) {//Get Memcachedmanager instance Memcachedmanager cache =              Memcachedmanager.getinstance ();       1 Insert list<records> recordslist = new arraylist<records> ();       for (int i =0; i<5; i++) {Records Records = new Records ();              Records.setpagesize (i);       Recordslist.add (Records);       Cache.Add ("Select AAA from BBB WHERE" +i,records);              } System.out.println ("Insert completed ==>"); 2 Get for (int i =0; i<9; i++) {Records Records = (Records) cache.get ("Select AAA from BBB WHERE"              +i);        if (null = = Records) {System.out.println ("DAO Layer re-check");       } else {String str = records.getpagesize (). toString ();       System.out.println ("the collection obtained from the cache is:" + str); }       }    }} 



Four: Phenomenon

14:30:31 INFO Com.alisoft.xplatform.asf.cache.impl.defaultcacheimpl-defaultcache Checkservice is start!
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ serializing for key:select+ Aaa+from+bbb+where+0 for Class:com.tianditu.entity.attrGrid.Records
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ memcache cmd (Result code): a DD select+aaa+from+bbb+where+0 8 0 451
(STORED)
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ data successfully stored for Key:select+aaa+from+bbb+where+0
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ serializing for key:select+ Aaa+from+bbb+where+1 for Class:com.tianditu.entity.attrGrid.Records
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ memcache cmd (Result code): a DD select+aaa+from+bbb+where+1 8 0 451
(STORED)
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ data successfully stored for Key:select+aaa+from+bbb+where+1
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ serializing for key:select+ Aaa+from+bbb+where+2 for Class:com.tianditu.entity.attrGrid.Records
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ memcache cmd (Result code): a DD select+aaa+from+bbb+where+2 8 0 451
(STORED)
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ data successfully stored for Key:select+aaa+from+bbb+where+2
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ serializing for key:select+ Aaa+from+bbb+where+3 for Class:com.tianditu.entity.attrGrid.Records
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ memcache cmd (Result code): a DD select+aaa+from+bbb+where+3 8 0 451
(STORED)
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ data successfully stored for Key:select+aaa+from+bbb+where+3
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ serializing for key:select+ Aaa+from+bbb+where+4 for Class:com.tianditu.entity.attrGrid.Records
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ memcache cmd (Result code): a DD select+aaa+from+bbb+where+4 8 0 451
(STORED)
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ data successfully stored for Key:select+aaa+from+bbb+where+4
Insert Complete ==>
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ deserializing class Com.tianditu.entity.attrGrid.Records
The collection obtained from the cache is: 0
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ deserializing class Com.tianditu.entity.attrGrid.Records
The collection obtained from the cache is: 1
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ deserializing class Com.tianditu.entity.attrGrid.Records
The collection obtained from the cache is: 2
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ deserializing class Com.tianditu.entity.attrGrid.Records
The collection obtained from the cache is: 3
14:30:31 INFO com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient-++++ deserializing class Com.tianditu.entity.attrGrid.Records
Collection is made from cache: 4
DAO layer to check
DAO layer to check
DAO layer to check
DAO layer to check


Java + memcached Installation

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.