e a value (async) for one hour c.set("someKey", 3600, someObject); // Retrieve a value. Object myObject=c.get("someKey");
Advanced Usage
MemcachedClient may be processing a great deal of asynchronous messages or possibly dealing with an unreachable memcached, which may delay processing. If a memcached is disabled, for example, MemcachedConnection will continue to attempt to reconnect and replay pending operations until it comes back up. To prevent this from causing your application to hang, you can use one of the asynchronous mechanisms to time out a request and cancel the operation to the server.
// Get a memcached client connected to several servers MemcachedClient c=new MemcachedClient( AddrUtil.getAddresses("server1:11211 server2:11211")); // Try to get a value, for up to 5 seconds, and cancel if it doesn't return Object myObj=null; Future<Object> f=c.asyncGet("someKey"); try { myObj=f.get(5, TimeUnit.SECONDS); } catch(TimeoutException e) { // Since we don't need this, go ahead and cancel the operation. This // is not strictly necessary, but it'll save some work on the server. f.cancel(); // Do other timeout related stuff }