Sources: https://memcached.org/, http://libevent.org/
Building from source requires libevent module. which is an event notification library.
yum install memcached #install on Redhat(centos, fedora...)
apt-get install memcached #install on Ubuntu, debians..
memcached -u hadoop & # starts memcache in background as a non-root user "hadoop"
memcached <HOST>:11211 stats #shows stats.
memcached <HOST>:11211 display #shows slabs. or without display.
memcached <HOST>:11211 dump #dumps keys and values.
Java Clilent: #dependencies in build.gradle are : compile 'net.spy:spymemcached:2.9.1'
import java.io.IOException;
import java.net.InetSocketAddress;
import net.spy.memcached.MemcachedClient;
public class MemcacheClient {
public static void main(String[] args) throws IOException {
MemcachedClient client = new MemcachedClient(new InetSocketAddress("pig", 11211));
System.out.println(client.getStats());
client.shutdown();
}
}
#once client is initialized, it can be used as simple Map. set(String key, int Age[timestamp or seconds from now], Object anything) to store and get(String key) to fetch. Note any object that implement Serialzable interface can be set or get to or from memcached store. Happy coding...