php下Memcached入门实例解析

(编辑:jimmy 日期: 2024/9/29 浏览:2)

本文较为详细的讲述了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程序设计有所帮助。

Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。