时间:2021-07-01 10:21:17 帮助过:16人阅读
本文介绍了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 函数替换为
2、CI database/DB_cache.php 中 90行 read 函数 if (FALSE === ($cachedata = read_file($filepath))) 一行前面加上
这样,在需要开启缓存的地方,由以前的 $this→db→cache_on(); 修改为: $this→db→cache_on($SEC); $SEC 为缓存过期时间,以秒为单位。 例如,$this→db→cache_on(60);表示缓存60秒后过期。 |