无为清净楼资源网 Design By www.qnjia.com

本文较为详细的讲述了php下Memcached的入门知识与实例。分享给大家供大家参考。具体如下:

memcache 在什么情况下被使用,什么情况下不要使用"codetitle">复制代码 代码如下:<?php
class mycache
{
  private $cache;
  function  __construct()
  {
    $this->cache = new memcache();
    // you can replace localhost by memcached server ip addr and port no.
    $this->cache->connect('localhost', 10987);
  }
 
  function get_data($key)
  {
    $data = $this->cache->get($key);
    if($data != null)
      return $data;
    else
    {
      if($this->cache->getresultcode() == memcached::res_notfound)
      {
        //do the databse query here and fetch data
        $this->cache->set($key,$data_returned_from_database);
      }
      else
      {
        error_log('no data for key '.$key);
      }
    }
  }
}
$cache = mycache();
$cache->get_data('foo');
?>

希望本文所述对大家的php程序设计有所帮助。

标签:
php,Memcached,入门

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com