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
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:
<dependency> <groupId>com.googlecode.xmemcached</groupId> <artifactId>xmemcached</artifactId> <version>2.0.0</version> </dependency>
MemcachedClient client=new XMemcachedClient("host",11211); //store a value for one hour(synchronously). client.set("key",3600,someObject); //Retrieve a value.(synchronously). Object someObject=client.get("key"); //Retrieve a value.(synchronously),operation timeout two seconds. someObject=client.get("key",2000); //Touch cache item ,update it's expire time to 10 seconds. boolean success=client.touch("key",10); //delete value client.delete("key");