下面演示一个PHP实例:
<?php
$mem=new Memcache;$mem->connect("127.0.0.1",11211);$sql="select * from db_it168_cpu";$key=substr(md5($sql),10,8);$data=$mem->get($key);if(!$data){$mysqli=new mysqli("localhost","root","","computer");$result=$mysqli->query($sql);$data=array();while($row=$result->Fetch_assoc()){$data[]=$row;}$result->free();$mysqli->close();$mem->add($key,$data,MEMCACHE_COMPRESSED,3000);echo $sql;}print_r($data);
?>
这个代码很简单,只是一个说明例子,你懂的!