This does not work
$get_data_qry = "SELECT * FROM list;";
$get_data_res = $db->Query($get_data_qry);
$key = 'someKey'; /** silly mistake corrected after being notified by comments*/
$get_data_res = $memcache->get($key);
if ($get_data_res) {
PushOutput($get_data_res);
echo "<br/>Directly from cache";
}
else {
$get_data_res = $db->Query($get_data_qry);
$memcache->set($key, $get_data_res, 0, 20000); /*Store the MySql resource in the cache*/
PushOutput($get_data_res);
}
I get the following message: PHP Warning: Memcache::set() expects parameter 1 to be string, resource given in E:\Repository\HTML\tooldent\songs\songList.tpl on line 54.
It seems weird, why a resource cannot be cached? Any alternatives?
If your $db construct use mysql_query:
A resultset is not a string and you set $key to the resultset at line 4.
Update:
Output:
But as far as I know you can’t treat this object as a normal mysql object:
You can try to create a multidimensional array out of the resultset for memcache.