How to let CodeIgniter database cache automatically expire_PHP tutorial

WBOY
Release: 2016-07-13 10:28:22
Original
987 people have browsed it

The CodeIgniter framework is a very small PHP framework. CI comes with a database file cache, but according to the official statement, the cache will never expire after being set unless you call a method to actively delete it.

Cache files DO NOT expire. Any queries that have been cached will remain cached until you delete them.

It feels too retarded and very inconvenient. Modify the db class, set an expiration time when caching is enabled, and the cache will automatically expire when it expires.

1: Replace the cache_on function in line 1021 of CI database/DB_dirver.php with

Copy code The code is as follows:
function cache_on($expire_time=0) //add parm expire time - cache expiration time
{
$this->cache_expire_time = $expire_time; //add by kenvin
$this-> ;cache_on = TRUE;
return TRUE;
}


2: CI database/DB_cache.php line 90 read function if (FALSE === ($cachedata = read_file($ filepath))) Add

in front of a line. Copy the code . The code is as follows:
//Determine whether it is expired// cache_expire_time
if ( !file_exists($filepath) ) {
return false;
}
if ( $this->db->cache_expire_time > 0 && filemtime($filepath) db->cache_expire_time ) {
return false;
}


In this way, where the cache needs to be enabled, the previous $this→db→cache_on(); is changed to
Copy code The code is as follows:
$this→db→cache_on($SEC);

$SEC is the cache expiration time, in seconds unit. For example, $this→db→cache_on(60); means that the cache will expire after 60 seconds.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/788633.htmlTechArticleCodeIgniter framework is a very small PHP framework. CI comes with a database file cache, but according to the official statement, the cache will never expire after being set unless you call a method to actively delete it. Cache...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!