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;
}
}


Comments
Comments are not available for this entry.
2024 By Angel Cool