Memcached简介

I am trying to use Memcached right now, and I am a little confuse about this:

First, do I need to make a class for Memcached? like this: click me! or is it automatically works? do I just need to make a connection to the memcached server and then I can cache data?

UPDATE

When I tried to use the code exiang provided, my output in all of the var_dumps are boolean false. Anybody knows why is this happened?

UPDATE PART 2

When I tried to use this code echo $m->getResultMessage()," "; it returns:

SERVER HAS FAILED AND IS DISABLED UNTIL TIMED RETRY

make sure you have enabled the php memcache module, it looks like this in your phpinfo enter image description here

Make sure your memcached server is running

Then, you can use it directly like this: http://php.net/manual/en/memcached.set.php

<?php
$m = new Memcached();
$m->addServer('localhost', 11211);

$m->set('int', 99);
$m->set('string', 'a simple string');
$m->set('array', array(11, 12));
/* expire 'object' key in 5 minutes */
$m->set('object', new stdclass, time() + 300);


var_dump($m->get('int'));
var_dump($m->get('string'));
var_dump($m->get('array'));
var_dump($m->get('object'));
?>