檔案緩存的php類別庫
<?php class CacheLayer{ protected $root = ""; protected $cache = ""; protected $key = ""; protected $life = 0; public function __construct($key, $root = "/cachelayer"){ $this->root = $_SERVER["DOCUMENT_ROOT"].$root; $this->key = $key; } public function expired($life_span){ $this->life = $life_span; $file = $this->root."/".$this->key.".cachelayer"; if(is_file($file)){ $mtime = filemtime($file); return (time() >= ($mtime + $this->life)); }else{ return true; } } public function put($content){ $file = $this->root."/".$this->key.".cachelayer"; if(!is_dir(dirname($this->root))){ return false; } $this->delete(); $content = json_encode($content); return (bool)file_put_contents($file, $content); } public function get(){ $file = $this->root."/".$this->key.".cachelayer"; if(is_file($file)){ return json_decode(file_get_contents($file), true); } return array(); } public function delete(){ $file = $this->root."/".$this->key.".cachelayer"; if(is_file($file)){ unlink($file); return true; } return false; } } ?>
這是一個很好用的PHP快取類別庫,需要的朋友可以下載使用,可以透過檔案緩存,大大緩解資料庫的壓力
免責聲明
本站所有資源皆由網友貢獻或各大下載網站轉載。請自行檢查軟體的完整性!本站所有資源僅供學習參考。請不要將它們用於商業目的。否則,一切後果都由您負責!如有侵權,請聯絡我們刪除。聯絡方式:admin@php.cn
相關文章

18Dec2024
從 PHP 中的其他類別存取 MySQLi 連線從 PHP 5.6 升級到 7.0 時,必須從 MySQL 過渡到 MySQLi。這...

13Nov2024
使用 PHP 解析 CSS 檔案:使用“postclass”選擇性地提取類別問題:您尋求一種方法來解析 PHP 中的 CSS 檔案並提取每個...

26Oct2024
使用 PHP 解析 CSS 檔案在 PHP 中,解析 CSS 檔案需要特殊技術來擷取特定資訊。為了說明這一點,讓我們考慮...

15Nov2024
使用 PHP 解析 CSS 檔案使用 PHP,您可以解析 CSS 檔案以提取特定資訊。本文將引導您完成自訂...


熱工具

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
18Mar2025手游攻略
倉庫:如何復興隊友
04Mar2025手游攻略
Hello Kitty Island冒險:如何獲得巨型種子
05Mar2025手游攻略
擊敗分裂小說需要多長時間?
07Mar2025手游攻略
R.E.P.O.保存文件位置:在哪里以及如何保護它?
06Mar2025故障排查