WordPress缓存类WP_Object_Cache

作者:matrix 被围观: 5,532 次 发布时间:2015-07-31 分类:Wordpress 零零星星 | 10 条评论 »

这是一个创建于 3190 天前的主题,其中的信息可能已经有所发展或是发生改变。

WordPress缓存WP_Object_Cache将数据缓存在内存中,每次请求,都会重新生成缓存。如果服务器支持内存缓存,如memcache 将会提高效率(相同页面处的多次查询数据)。减少数据库的请求次数。流量不大的用处也就不是很明显。
总的来说,没啥用。留作零碎记录

相关函数:

wp_cache_add($key, $data, $flag = '', $expire = 0);//添加缓存
wp_cache_get($key, $flag = '');//得到缓存,没有则返回false
//$key 自定义缓存名称
//$data 缓存数据
//$expire == 缓存 时间 部分可用
//$group $expire 都是可选参数

例子:

if(!$most_viewed = wp_cache_get('widgetPostsViewEcho', 'CACH_DATAViewPosts'))
{
    $most_viewed = $wpdb->get_results(".............");// database query
    wp_cache_add('widgetPostsViewEcho', $most_viewed, 'CACH_DATAViewPosts',36000);
}
if ($most_viewed) {
    foreach ($most_viewed as $viewed) {
        $post_ID    = $viewed->ID;
        $post_views = number_format($viewed->views);
        $post_title = esc_attr($viewed->post_title);
        $get_permalink = esc_attr(get_permalink($post_ID));
        $output .= "<li><a href=\"$get_permalink\">$post_title</a>";
        if ($show_date) {
            $posted = date(get_option('date_format'), strtotime($viewed->post_date));
            $output .= "$beforedate $posted $afterdate";
        }
        $output .= "$beforecount $post_views $aftercount</li>";
    }
}

参考:http://immmmm.com/open-WordPress-object-cache.html
http://www.jb51.net/cms/148531.html
http://www.lianyue.org/2011/2211/

其他文章:
本文固定链接:https://www.hhtjim.com/wordpress-wp_object_cache-cache-class.html
matrix
本文章由 matrix 于2015年07月31日发布在Wordpress, 零零星星分类下,目前没有通告,你可以至底部留下评论。
转载请注明:WordPress缓存类WP_Object_Cache-HHTjim'S 部落格
关键字:, , ,

有10 条评论 »

  1. pizap pizap 2016-12-23 15:46:45 +0800#6

    It is a great article. You will surely like this also because it is a great stuff, yeah it’s give us lots of interest and pleasure. Their opportunities are so fantastic and working style so speedy. Thank you for sharing the nice article. 😀 🙂

  2. 煮蛋器什么牌子好 煮蛋器什么牌子好 2016-9-12 20:56:48 +0800#5

    这个缓存基本没啥用吧。。。

  3. 香菇肥牛 香菇肥牛 2016-2-8 22:50:32 +0800#4

    新年快乐~愿贵站新年越来越红火 🙂

    • Matrix Matrix Moderator 2016-2-8 23:30:23 +0800

      谢谢 香菇肥牛 。‘
      😀 😀 新年快乐!

  4. 流量经营 流量经营 2015-8-26 14:30:43 +0800#3

    技术,感谢分散

  5. 东北人博客 东北人博客 2015-8-19 10:14:57 +0800#2

    我用的是 wp super 总感觉没有好的可以用 国人能做过简单的就好了

  6. 灰常记忆 灰常记忆 2015-8-5 17:55:51 +0800#1

    这个和WP Super Cache有区别吗?

    • Matrix Matrix Moderator 2015-8-5 19:56:43 +0800

      这玩意 我觉得有点鸡肋。或许我不知道怎么更好的用它
      WP Super Cache 是wp插件诶,这个可不是,它只是一个php类

    • Matrix Matrix Moderator 2015-8-5 19:57:31 +0800

      是群函数吧 哎 差不多

添加新评论 »

 🙈 😱 😂 😛 😭 😳 😀 😆 👿 😉 😯 😮 😕 😎 😐 😥 😡 😈 💡

插入图片

NOTICE: You should type some Chinese word (like “你好”) in your comment to pass the spam-check, thanks for your patience!