欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

讓CodeIgniter數(shù)據(jù)庫緩存自動過期的處理的方法

 更新時(shí)間:2014年06月12日 10:12:32   投稿:shichen2014  
按官方的說法,緩存設(shè)置后永不過期,除非你調(diào)用方法主動刪除。這篇文章主要介紹了CodeIgniter數(shù)據(jù)庫緩存自動過期的處理,需要的朋友可以參考下
CodeIgniter框架是一個(gè)非常小巧的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í)設(shè)置一個(gè)過期時(shí)間,到期自動緩存自動失效。

1:CI database/DB_dirver.php 中 1021行 cache_on 函數(shù)替換為

復(fù)制代碼 代碼如下:
function cache_on($expire_time=0) //add parm expire time - 緩存過期時(shí)間
{
$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;
}


這樣,在需要開啟緩存的地方,由以前的 $this→db→cache_on(); 改為
復(fù)制代碼 代碼如下:
$this→db→cache_on($SEC);

$SEC 為緩存過期時(shí)間,以秒為單位。 如 $this→db→cache_on(60);表示緩存60秒后過期。

相關(guān)文章

最新評論