connect('localhost', 11211) or die ("Could not connect");
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = time();
$key_string = 'abc';
$get_result = $memcache->get($key_string);
if(strlen($get_result) > 0) {
echo "Data from the cache:
\n";
var_dump($get_result);
exit(0);
}
$memcache->set($key_string, $tmp_object, false, 5) or die ("Failed to save data at the server using key: $key_string");
echo "Stored data in the cache (data will expire in 5 seconds)
\n";
$get_result = $memcache->get($key_string);
echo "Fetched key '$key_string' from the cache:
\n";
var_dump($get_result);
?>