codeigniter 数据库缓存

CI默认的cache_on 一旦开启,永远不失效,除非自己删除。比较弱智。
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;

 

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

//判断是否过期 // cache_expire_time if ( !file_exists($filepath) ) { return false; } if ( $this->db->cache_expire_time > 0 && filemtime($filepath) < time() - $this->db->cache_expire_time) { return false; }

 

 

在需要开启数据库缓存的地方写: $this→db→cache_on($SEC); $SEC 为需要缓存的秒数。 0 为永不过期。 如 $this→db→cache_on(3); 表示缓存3秒。3秒后自动失效。

 

转载自:红麦软件 http://www.teamwiki.cn/

你可能感兴趣的:(数据库,cache,file,function,php)