wordpress自带的缓存性能应用引见

用动态化当然能够处理这些成绩,不过关于流量不大的博客就没必要了。 wordpress自带有缓存体系,要害的函数你能够在wp-includes/cache.php或 Codex里查找到一切的函数。


你能够应用下列函数来完成增加缓存。


wp_cache_add($key, $data, $flag = '', $expire = 0)

相同的,要删除缓存数据能够经过上面的办法完成。

wp_cache_delete($id, $flag = '')

提取缓存数据:

wp_cache_get($id, $flag = '')

交换缓存数据:

wp_cache_replace($key, $data, $flag = '', $expire = 0)

 
举个例子,假如想输入**评论,能够先从缓存里读取需求输入的HTML,假如没有,申请一次,胜利后退出缓存,当然工夫能够管制。
我晓得有很多**评论,相干文章免插件输入的办法,原理都一样,能够自行改改,贴个我用的:
config.php外面增加

define('WP_CACHE', true);

假如你用了其它缓存插件,根本上这个就没成果了。由于这些插件有相似的办法。


<?php
/**
* get recent comments
* @param unknown_type $args
* @return unknown_type
*/
function DeamworkRecentcomments($args='number=5&status=approve'){</p> <p> $cacheID = md5($args);
//有缓存就间接输入
if($output = wp_cache_get('recentComments_'.$cacheID, 'Winysky')){
echo $output;
return;
}</p> <p> //$rcms = get_comments($args);
global $wpdb;</p> <p> $my_email = "'" . get_bloginfo ('admin_email') . "'";
//主动获取博主邮箱
$rcms = $wpdb->get_results("
SELECT ID, post_title, comment_ID, comment_author, comment_author_email, comment_content
FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts
ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
WHERE comment_approved = '1'
AND comment_type = ''
AND post_password = ''
AND comment_author_email != $my_email</p> <p>ORDER BY comment_date_gmt
DESC LIMIT 10</p> <p>");</p> <p> //print_r($rcms);return;
if(empty($rcms)){
_e('没无数据');
return;
}
//历遍数据
$output = '';
foreach( $rcms as $rcm ){
$author = $rcm->comment_author;
//if($author =='admin'){continue;}
$content = DeamworkStriptags( $rcm->comment_content);
$the_title = get_the_title($rcm->comment_post_ID);
$s_excerpt = convert_smilies( DeamworkSubstr( $content, 200 ) );
$contents = '<span class=\'recentcommentslink_author\'>' . $author . '</span> <span class=\'recentcommentslink_on\'>on</span> <span class=\'recentcommentslink_title\'>' . $the_title . '</span><p class=\'recentcommentslink_excerpt\'>' . get_avatar($rcm->comment_author_email, 64). $s_excerpt . '</p>';</p> <p> $output .= '<li><p id="C_' . $rcm->comment_ID . '_d" style="display:none">' . $contents . '</p>' . '<a id="C_' . $rcm->comment_ID . '" class="recentcommentslink" href="' . get_permalink($rcm->comment_post_ID) . '#comment-' . $rcm->comment_ID . '" >' . get_avatar($rcm->comment_author_email, 32) . '</a></li>';</p> <p> }
//输入后退出缓存
wp_cache_add('recentComments_'.$cacheID,$output, 'Deamwork');
echo $output;
}

最初,试试成果吧~

以上就是安达网络工作室关于《wordpress自带的缓存功能使用介绍》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: wordpress缓存 wp_cache WordPress
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
WordPress菜单CSS类选项设置办法

WordPress菜单CSS类选项设置办法: 1、点开WordPress菜单设置页面右上角&ldquo;显示选项&rdquo;,勾选外面的...

详解WordPress中简码格局标签编写的根本办法

WordPress 简码是一品种似于论坛标签的货色,格局相似于把尖括号换成中括号的 Html 标签。简码很多人叫做短...

wordpress定时义务(wp-cron.php)造成主机CPU比拟高的处理方法

自从用了阿里云主机,真是没有省心过。 这两天网站CPU天天100+的,过一会就挂了,原来是wp-cron.php文件造成...

Wordpress主动将蕴含长链接的评论标志为渣滓评论的办法

本文实例讲述了Wordpress主动将蕴含长链接的评论标志为渣滓评论的办法。分享给大家供大家参考。详细剖析如下...

WordPress中主动激活插件的完成办法

有一个一劳永逸的办法能够使wordpress博主当前上传插件都不必再手动激活,wordpress主动激活,办法很简略,...

WordPress中文截取函数用法剖析

本文实例讲述了WordPress中文截取函数用法。分享给大家供大家参考。详细剖析如下: 很多冤家间接应用php su...

需求提交

客服服务

亿鸽在线客服系统