求一个php数据缓存类,谢谢!
有例子更好啊

解决方案 »

  1.   


    <?php
    class Data_cache
    {
    //缓存文件存放的地址
       private $file = "/usr/www/program/cache/";
       
       //文件的名称
       private $filename = "filename";
       
       //需要写入缓存文件的数据
       private $data = "";
       
       public function __construct($filename,$data)
       {
        $this->filename = $filename;
        $this->data = $data;
       
        if($this->judge_cache_file_exists())
        {
        $this->put_data_to_file();
        }
       }
       
       //写入缓存文件
       public function put_data_to_file($data)
       {
        if(isset($data))
        {
        $dir = $file.md5($filename).".php";
       
        file_put_contents($dir,$this->data);
        }else{
        return FALSE;
        }
       }
       
       //判断缓存文件是否存在
       public function judge_cache_file_exists()
       {
        return file_get_contents($file.md5($filename).".php",$this->data);
       }
    }?>
      

  2.   


    $data = "这是需要缓存的数据";
    $filename = "filename";
    $cache = new Data_cache($filename,$data);