title: How to cache a Memcached connection using the java spymemcached client
body: <p>I am learning how to cache objects using memcached with the spymemcached client from <a href="http://code.google.com/p/spymemcached/wiki/Examples" rel="nofollow noreferrer">spymemcached examples</a></p>
  
  <pre><code>MemcachedClient c=new MemcachedClient(new InetSocketAddress("hostname", portNum));    
  // Store a value (async) for one hour
  c.set("someKey", 3600, someObject);
  // Retrieve a value (synchronously).
  Object myObject=c.get("someKey");
  </code></pre>
  
  <p>I have noted that each time I want to cache or retrieve an object I create a new memcached client which am assuming is a new connection and that memcached has no connection pooling mechanism therefore users are advised to cache the connections to decrease overhead for reconnecting from this question <a href="https://stackoverflow.com/questions/8683142/memcached-client-opening-closing-and-reusing-connections">opening closing and reusing connections</a>.</p>
  
  <p>My question is how do I cache this connection? Can someone please give me an example I can start from. 
  If you are wondering what I have tried, I tried to put my connection in the memcached but then I realized that I have to create a connection to get it. :) </p>
  
  <p>Thanks in advance.</p>