国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 PHP 函式庫 其它類別庫 檔案緩存的php類別庫
檔案緩存的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;
  }
}
?>

這是一個(gè)很好用的PHP快取類別庫,需要的朋友可以下載使用,可以透過檔案緩存,大大緩解資料庫的壓力

免責(zé)聲明

本站所有資源皆由網(wǎng)友貢獻(xiàn)或各大下載網(wǎng)站轉(zhuǎn)載。請自行檢查軟體的完整性!本站所有資源僅供學(xué)習(xí)參考。請不要將它們用於商業(yè)目的。否則,一切後果都由您負(fù)責(zé)!如有侵權(quán),請聯(lián)絡(luò)我們刪除。聯(lián)絡(luò)方式:admin@php.cn

相關(guān)文章

如何從不同的 PHP 類別正確存取 MySQLi 資料庫連線? 如何從不同的 PHP 類別正確存取 MySQLi 資料庫連線?

18 Dec 2024

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

為什麼要從 Python 中的「object」繼承:一個(gè)類別繼承問題 為什麼要從 Python 中的「object」繼承:一個(gè)類別繼承問題

24 Dec 2024

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

如何使用 PHP 從 CSS 檔案中提取包含「postclass」的類別? 如何使用 PHP 從 CSS 檔案中提取包含「postclass」的類別?

13 Nov 2024

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

如何使用 PHP 從 CSS 檔案中提取特定的類別名稱? 如何使用 PHP 從 CSS 檔案中提取特定的類別名稱?

26 Oct 2024

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

如何在 Linux 上建立和使用動態(tài)共用 C 類別庫? 如何在 Linux 上建立和使用動態(tài)共用 C 類別庫?

05 Dec 2024

在 Linux 上建立和使用動態(tài)共用 C 類別庫建立共用類別庫要建立共用 C 類別庫,您可以依照...

為什麼無法在字段初始化程序中初始化非靜態(tài)字段? 為什麼無法在字段初始化程序中初始化非靜態(tài)字段?

03 Jan 2025

了解欄位初始化問題在您的程式碼中,您有一個(gè)儲存庫類別 (DinnerRepository) 和一個(gè)服務(wù)類別 (Service),它使用...

See all articles