PHP: Caching MySQL queries in Memcached 
Using PHP memcache client:
	
public function doFetchRecords(){

$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect to Memcached.");

$SQL="SELECT * FROM statistics";
$key = md5($SQL);
$get_result = $memcache->get($key);

if ($get_result) {
echo '<!--Memcache Data-->';
return $get_result;
}
else {
$this->db->setQuery($SQL);
$data=$this->db->executeQuery(true);
$memcache->set($key, $data, 0, 30); // Store the result of the query for 30 seconds
return $data;
}
}


[ view entry ] ( 3084 views )   |  print article

<<First <Back | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Next> Last>>



2025 By Angel Cool