讓CodeIgniter數(shù)據(jù)庫緩存自動過期的處理的方法
更新時間:2014年06月12日 10:12:32 投稿:shichen2014
按官方的說法,緩存設(shè)置后永不過期,除非你調(diào)用方法主動刪除。這篇文章主要介紹了CodeIgniter數(shù)據(jù)庫緩存自動過期的處理,需要的朋友可以參考下
CodeIgniter框架是一個非常小巧的PHP框架。CI自帶數(shù)據(jù)庫文件緩存,但按官方的說法,緩存設(shè)置后永不過期,除非你調(diào)用方法主動刪除。
Cache files DO NOT expire. Any queries that have been cached will remain cached until you delete them.
感覺太弱智了,非常不方便。 修改一下db類,在開啟緩存時設(shè)置一個過期時間,到期自動緩存自動失效。
1:CI database/DB_dirver.php 中 1021行 cache_on 函數(shù)替換為
2:CI database/DB_cache.php 中 90行 read 函數(shù) if (FALSE === ($cachedata = read_file($filepath))) 一行前面加上
這樣,在需要開啟緩存的地方,由以前的 $this→db→cache_on(); 改為
$SEC 為緩存過期時間,以秒為單位。 如 $this→db→cache_on(60);表示緩存60秒后過期。
Cache files DO NOT expire. Any queries that have been cached will remain cached until you delete them.
感覺太弱智了,非常不方便。 修改一下db類,在開啟緩存時設(shè)置一個過期時間,到期自動緩存自動失效。
1:CI database/DB_dirver.php 中 1021行 cache_on 函數(shù)替換為
復(fù)制代碼 代碼如下:
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;
}
{
$this->cache_expire_time = $expire_time; //add by kenvin
$this->cache_on = TRUE;
return TRUE;
}
2:CI database/DB_cache.php 中 90行 read 函數(shù) if (FALSE === ($cachedata = read_file($filepath))) 一行前面加上
復(fù)制代碼 代碼如下:
//判斷是否過期 // cache_expire_time
if ( !file_exists($filepath) ) {
return false;
}
if ( $this->db->cache_expire_time > 0 && filemtime($filepath) db->cache_expire_time) {
return false;
}
if ( !file_exists($filepath) ) {
return false;
}
if ( $this->db->cache_expire_time > 0 && filemtime($filepath) db->cache_expire_time) {
return false;
}
這樣,在需要開啟緩存的地方,由以前的 $this→db→cache_on(); 改為
復(fù)制代碼 代碼如下:
$this→db→cache_on($SEC);
$SEC 為緩存過期時間,以秒為單位。 如 $this→db→cache_on(60);表示緩存60秒后過期。
您可能感興趣的文章:
- CodeIgniter配置之a(chǎn)utoload.php自動加載用法分析
- CI框架中類的自動加載問題分析
- CI框架自動加載session出現(xiàn)報錯的解決辦法
- CI框架實現(xiàn)創(chuàng)建自定義類庫的方法
- 詳談配置phpstorm完美支持Codeigniter(CI)代碼自動完成(代碼提示)
- CodeIgniter自定義控制器MY_Controller用法分析
- CodeIgniter實現(xiàn)從網(wǎng)站抓取圖片并自動下載到文件夾里的方法
- CodeIgniter采用config控制的多語言實現(xiàn)根據(jù)瀏覽器語言自動轉(zhuǎn)換功能
- codeigniter自帶數(shù)據(jù)庫類使用方法說明
- 解析CodeIgniter自定義配置文件
- php框架CI(codeigniter)自動加載與自主創(chuàng)建對象操作實例分析
相關(guān)文章
CentOS 上搭建 PHP7 開發(fā)測試環(huán)境
本文給大家分享的是作者在centos上搭建部署php7的開發(fā)測試環(huán)境的全部過程,非常的細致,有需要的小伙伴可以參考下2017-02-02深入淺析php中sprintf與printf函數(shù)的用法及區(qū)別
這篇文章主要介紹了php中sprintf與printf函數(shù)的用法及區(qū)別,涉及到printf函數(shù)、sprintf函數(shù)相關(guān)資料,需要的朋友可以參考下2016-01-01