Original: Java operations memcached Getting Started tutorial demo code
Source code: Http://www.zuidaima.com/share/1550463754996736.htm
Reference Address:
Http://www.open-open.com/lib/view/open1357831114183.html
http://tech.idv2.com/2008/07/10/memcached-001/
Thank you-java Niu-id No. 1 Thank you Tin-superprivate-195
Search the online part of the code, a very simple demo, the result set of the query into the cache. I do not understand, you can search for information, but after joining Memcached, the speed of project access did increase
Package Com.dream.core.util;import Java.util.date;import Com.danga.memcached.memcachedclient;import com.danga.memcached.sockiopool;/** * @describe: Memoryutil.java * * @date 2013-9-30 * @author yuanlin.su www.zuidaima.com * Reference Address: http://www.open-open.com/lib/view/open1357831114183.html * http://tech.idv2.com/2008/07/10/memcached-001/* Thank you-java niu-id No. 1 * Thank you Tin-superprivate-195 * * Service end and JAR package free points: http://download.csdn.net/detail/consuy/6341989 */public class Me Moryutil {private static memcachedclient client = Null;private final static String Cache_isopen_key = "Cache_isopen";/** * Initialize Memcache tool */public synchronized static void init (String ipAddress) {if (client = = null) {string[] servers = {Ipaddre SS};integer[] weights = {1}; Sockiopool pool = sockiopool.getinstance ();p ool.setservers (servers);p ool.setweights (weights);p Ool.setnagle (False) ;p Ool.setsocketto (10000);p Ool.setsocketconnectto;p ool.initialize (); client = new Memcachedclient (); Set (CACHE _isopen_key, 1);}} /** * Set Value * * @paramKey * @param value */public static void set (String key, Object value) {Client.set (key, value);} /** * Set value at the same time add validity period * * @param key * @param value * @param minute minutes */public static void set (String key, Object value, int minute) {Client.set (key, value, new Date (System.currenttimemillis () + minute * 1000l));} /** * Check if the value exists * * @param key * @return */public static Boolean keyexists (String key) {return client.keyexists (key);} /** * Delete the value of the memory data item * * @param key */public static void Delete (String key) {client.delete (key);} /** * Clears all data */public static void Clear () {Client.flushall ();} /** * Querying object information from memory * * @param key * @return */@SuppressWarnings ("unchecked") public static <T> T get (String key) {Retu RN (T) client.get (key);} /** * Determine if memcache has been turned on * * @return */public static Boolean Cacheisopen () {if (keyexists (Cache_isopen_key)) {return true;} else {return false;}} Demo/*public Modelandview Publishmood (@ModelAttribute ("form") UserInfo user, HttpServletRequest request) {// Todoobject<t&gT obj = Memoryutil.get (key), if (obj = = null) {object<t> obj = Service.find (entity.class); Memoryutil.set (key, obj);} REUTRN null;} */}
Java Operations memcached Getting Started tutorial demo code