(This is an old question, but I wanted to provide somewhat of an answer for future visitors.)
The following should do what you want:
$cache = new fCache('xcache');
$sql = $db->escape("SELECT foo, bar FROM baz WHERE id = %i", $id);
$sql_hash = md5($sql);
if (!$data = $cache->get($sql_hash)) {
$data = $db->query($sql)->fetchAllRows();
$cache->set($sql_hash, $data, 120);
}
// Use the result
If you are looking to do this for all results, you are probably going to want to write a helper class. Using fDatabase::escape() creates a fully-formed SQL statements that includes all values. This is essential so you get a different hash for different IDs.
If you are doing this for a lot of records you are going to want to keep an eye on the usage of xcache.