A method for processing CodeIgniter database cache to expire automatically _php instance

Source: Internet
Author: User
Tags php framework codeigniter
The CodeIgniter framework is a very compact PHP framework. CI has its own database file cache, but according to the official view, the cache setting never expires unless you invoke the method to delete it voluntarily.

Cache files do not expire. Any queries that have been cached'll remain cached until you delete them.

It's so retarded, it's very inconvenient. Modify the DB class, set an expiration time when the cache is turned on, automatically expire automatically when the cache expires.

The 1021 line cache_on function in 1:ci database/db_dirver.php is replaced by the

Copy Code code as follows:
function cache_on ($expire _time=0)//add parm expire time-cache expiration
{
$this->cache_expire_time = $expire _time; Add by Kenvin
$this->cache_on = TRUE;
return TRUE;
}


2:ci database/db_cache.php 90 rows of the Read function if (FALSE = = ($cachedata = Read_file ($filepath))) preceded by a line plus

Copy Code code as follows:
Determine if expiration//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 opened, the previous $this →db→cache_on (); To
Copy Code code as follows:
$this →db→cache_on ($SEC);

$SEC is the cache expiration time, in seconds. such as $this →db→cache_on (60), which indicates that the cache expires after 60 seconds.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.