檔案緩存的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 檔案以提取特定資訊。本文將引導您完成自訂...


熱工具

熱門文章
兩個點博物館:邦格荒地地點指南
28 Feb 2025
手游攻略
擊敗分裂小說需要多長時間?
07 Mar 2025
手游攻略
在哪裡可以在怪物獵人荒野中找到地球晶體
27 Feb 2025
手游攻略
倉庫:如何復興隊友
04 Mar 2025
手游攻略
Hello Kitty Island冒險:如何獲得巨型種子
05 Mar 2025
手游攻略