codeigniter資料庫緩衝自動到期處理方法

來源:互聯網
上載者:User
本文介紹了codeigniter資料庫緩衝自動到期的處理辦法,修改了一下db類,在開啟緩衝時設定一個到期時間,到期自動緩衝自動失效。

codeigniter資料庫緩衝自動到期

codeigniter架構是一個非常小巧的php架構,最近幾個項目中一直用。ci內建資料庫檔案緩衝,但按官方的說法,緩衝設定後永不到期,出發你調用方法主動刪除。

cache files do not expire. any queries that have been cached will remain cached until you delete them.

修改了一下db類,在開啟緩衝時設定一個到期時間,到期自動緩衝自動失效。

1、CI database/DB_dirver.php 中 1021行 cache_on 函數替換為

function cache_on($expire_time=0) //add parm expire time - 緩衝到期時間{$this->cache_expire_time = $expire_time; //add by kenvin$this->cache_on = TRUE;return TRUE;}

2、CI database/DB_cache.php 中 90行 read 函數 if (FALSE === ($cachedata = read_file($filepath))) 一行前面加上

//判斷是否到期 // cache_expire_timeif ( !file_exists($filepath) ) {return false;} // bbs.it-home.orgif ( $this->db->cache_expire_time > 0 && filemtime($filepath) db->cache_expire_time) {return false;}

這樣,在需要開啟緩衝的地方,由以前的 $this→db→cache_on(); 修改為:$this→db→cache_on($SEC); $SEC 為緩衝到期時間,以秒為單位。例如,$this→db→cache_on(60);表示緩衝60秒後到期。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.