Getting started

dennis zhuang edited this page Jul 28, 2016 · 1 revision

Dependencies

Xmemcached use slf4j for logging.

If you are using maven to build your project,you would just add a dependence with xmemcached:

  <dependency>
       <groupId>com.googlecode.xmemcached</groupId>
       <artifactId>xmemcached</artifactId>
       <version>${version}</version>
  </dependency>

Simple Example

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");
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.