下面是一個php快取檔案實作類別,根據我的經驗,快取檔案是根據使用者佈建的時間與檔案產生的日間以及目前時間進行比較,然後再判斷是否需要重建快取檔案。*/
下面是一個php教程快取檔案實作類別,根據我的經驗,快取檔案是根據使用者佈建的時間與檔案產生的日間以及目前時間進行比較,然後再判斷是否需要重建快取檔案。*/
class pagecache {
/**
* @var string $file 快取檔案地址
* @access public
*/
public $file;
/**
* @var int $cachetime 緩衝時間
* @access public
*/
public $cachetime = 3600;
/**
* 建構函式
* @param string $file 快取檔案地址
* @param int $cachetime 緩衝時間
*/
function __construct($file, $cachetime = 3600) {
$this->file = $file;
$this->cachetime = $cachetime;
}
/**
* 取緩衝內容
* @param bool 是否直接輸出,true直接轉到快取頁面,false返回緩衝內容
* @return mixed
*/
public function get($output = true) {
if (is_file($this->file) && (time()-filemtime($this->file))<=$this->cachetime && !$_get['nocache']) {
if ($output) {
header('location:' . $this->file);
exit;
} else {
return file_get_contents($this->file);
}
} else {
return false;
}
}
/**
* 設定緩衝內容
* @param $content 內容html字串
*/
public function set($content) {
$fp = fopen($this->file, 'w');
fwrite($fp, $content);
fclose($fp);
}
}
http://www.bkjia.com/PHPjc/444822.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444822.htmlTechArticle下面是一個php快取檔案實作類別,根據我的經驗,快取檔案是根據使用者佈建的時間與檔案產生的日間以及目前時間進行比較,然後再判斷是否...