Memcache Using Java - Java

Memcache Using Java

Snippet Code


  
Rate this page :
  [ 0 votes]

Download the jar file for memecache and set correct classpath.

import net.spy.memcached.MemcachedClient; public class MonIn implements java.io.Serializable{ Connection conn; private int urlid; private String er; private static MemcachedClient c = null; static { try { c = new MemcachedClient(new InetSocketAddress("127.0.0.1",11211)); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } } public float[][] avgInfo(String query) throws IOException{ String key=query; System.out.println(key); if(c.get(key)==null amp&key.equals(query)) { //your code c.set(key, 3600, info); return info; } else{ return (float[][]) c.get(key); } } }

Tags


Ask Questions

Ask Question