search
Homephp教程php手册让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 函数替换为

复制代码 代码如下:

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 中 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) db->cache_expire_time) {
return false;
}



这样,在需要开启缓存的地方,由以前的 $this→db→cache_on(); 改为

复制代码 代码如下:

$this→db→cache_on($SEC);


$SEC 为缓存过期时间,以秒为单位。 如 $this→db→cache_on(60);表示缓存60秒后过期。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)