J2EE use memcached tutorial

Written .

What is Memcached?

Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages.

Install Memcache on Ubuntu 12.04

To start, install memcached via apt-get
sudo apt-get install memcached

Check Memcached run state
netstat -lntp

J2EE project using XMemcached

We use XMemcached client for java.It is a high performance, easy to use multithreaded memcached client in java.

We j2ee project use maven build,you can try it now:


Simple Example

MemcachedClient client=new XMemcachedClient("host",11211);

//store a value for one hour(synchronously).
//Retrieve a value.(synchronously).
Object someObject=client.get("key");
//Retrieve a value.(synchronously),operation timeout two seconds.

//Touch cache item ,update it's expire time to 10 seconds.
boolean success=client.touch("key",10);

//delete value
comments powered by Disqus