我有一个从数据库返回的结果集。如何使用wp\\u缓存来加快速度?
function bb_attachments_cache() {
global $wp, $bp, $wpdb, $posts, $bb_attachments, $bb_attachments_cache, $bbdb;
$all_posts_query = "SELECT `post_id` FROM $bbdb->posts";
$posts = $bbdb->get_results( $all_posts_query );
foreach ($posts as $post) {
$bb_attachments_cache[$post->post_id] = array();
}
$sql = "SELECT
bba.id,
bba.time,
bba.post_id,
bba.user_id,
bba.user_ip,
bba.status,
bba.downloads,
bba.size,
bba.ext,
bba.mime,
bba.filename
FROM bb_posts bbp
JOIN bb_attachments bba
ON bba.post_id = bbp.post_id
ORDER BY id DESC";
$attachments = $wpdb->get_results($sql);
if ($attachments){
foreach ($results as $result){
$bb_attachments_cache[$result->post_id][$result->id] = $result;
}
unset($attachments);
}
}
如果附件表有任何更新,我想设置缓存对象。我使用wordpress 3.1,并安装了一个缓存插件。