CodeIgniter数据库缓存自动过期的处理
1:CI database/DB_dirver.php 中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 中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) db->cache_expire_time) {
return false;
}
这样,在需要开启缓存的地方,由以前的 $this→db→cache_on(); 改为
$this→db→cache_on($SEC);
$SEC 为缓存过期时间,以秒为单位。 如 $this→db→cache_on(60);表示缓存60秒后过期
我知道很多人在找这个东西 是不是? 这个很早之前就已经有人发过了,不过还是非常感谢楼主分享,期待楼主其他更好的分享 作个记号 mark一下 标记一下,下次使用尝试一下
页:
[1]