function sql_cache($query){ //sql 缓存文件形式 2016.3.18.abel
global $db;
$file = '../cache/sql_'.md5($query).'.txt';
$expire = 86400; // 24 小时
if (file_exists($file) &&
filemtime($file) > (time() - $expire)) {
$records = unserialize(file_get_contents($file));
return $records;
} else {
$products = $db->Execute($query);
while (!$products->EOF) {
$records[] = $products->fields;
$products->MoveNext();
}
$OUTPUT = serialize($records);
$fp = fopen($file,"w");
fputs($fp, $OUTPUT);
fclose($fp);
return $records;
} // end else
}
$db是框架里的sql类。