简单实例php 缓存文件生成技术实例_PHP教程

WBOY
發布: 2016-07-20 11:07:11
原創
798 人瀏覽過

简单实例php教程 缓存文件生成技术实例
class Cache
{
 protected $_cacheDir;

 public function __construct()
 {
  $this->_cacheDir = "./cache";
 }

 public function setCacheDir($cacheDir)
 {
  if(empty($cacheDir)){
   $this->_cacheDir = $this->_cacheDir;
  }else{
   $this->_cacheDir = $cacheDir;
  }
 }

 public function getCache($name)
 {
  $file_path = $this->_cacheDir.'/namma_cache-'.$name;
  if(!file_exists($file_path))
  {
   return false;
  }
  $handle = @fopen($file_path,'rb');
  $data = @fread($handle,filesize($file_path));
  return $this->unformatData($data);
  @flose($handle);
 }

 public function setCache($name,$data)
 {
  $file_path = $this->_cacheDir.'/namma_cache-'.$name;
  $data = $this->formatData($data);
  $fp = fopen($file_path, 'w');
        fwrite($fp,$data);
        fclose($fp);
        return $file_path;
 }

 public function formatData($data)
 {
  return serialize($data);
 }

 public function unformatData($data)
 {
  return unserialize($data);
 }
}


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444975.htmlTechArticle简单实例php教程 缓存文件生成技术实例 class Cache { protected $_cacheDir; public function __construct() { $this-_cacheDir = ./cache; } public function setCacheDir($c...
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!