檔案緩存的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
相關文章

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

24 Dec 2024
了解 Python 類別繼承在 Python 中,類別可以從其他類別繼承,這使它們能夠存取父類別的屬性並...

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

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

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


Hot Tools

熱門文章
丟失記錄:Bloom&Rage -Corey和Dylan的鎖組合
19 Feb 2025
手游攻略
王國來:拯救2-婚禮要買的衣服
05 Feb 2025
手游攻略
Hello Kitty Island冒險:重新啟動機器人任務演練
16 Feb 2025
手游攻略
丟失的記錄:Bloom&Rage-成就/獎杯指南
19 Feb 2025
手游攻略
王國來:拯救2-如何獲得Comfrey
07 Feb 2025
手游攻略