Ways to make CodeIgniter database cache automatic Expiration _php tutorial

Source: Internet
Author: User
Tags php framework codeigniter
The CodeIgniter framework is a very small PHP framework. The CI comes with the database file cache, but according to the official statement, the cache will never expire unless you invoke the method to delete it actively.

Cache files do not expire. Any queries that has been cached would remain cached until you delete them.

Feel too retarded, very inconvenient. Modify the DB class to set an expiration time when the cache is turned on, and the expiration auto-cache automatically expires.

1:ci database/db_dirver.php 1021 rows cache_on function is replaced by

Copy CodeThe code is 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-line read function if (FALSE = = = ($cachedata = Read_file ($filepath))) a line preceded by a

Copy CodeThe code is as follows://Determine whether to expire//Cache_expire_time
if (!file_exists ($filepath)) {
return false;
}
if ($this->db->cache_expire_time > 0 && filemtime ($filepath) db->cache_expire_time) {
return false;
}

Thus, where the cache needs to be opened, the previous $this →db→cache_on (); Switch
Copy CodeThe code is as follows: $this →db→cache_on ($SEC);
The $SEC is the cache expiration time, in seconds. such as $this →db→cache_on (60); Indicates that the cache expires after 60 seconds.

http://www.bkjia.com/PHPjc/788633.html www.bkjia.com true http://www.bkjia.com/PHPjc/788633.html techarticle The CodeIgniter Framework is a very small PHP framework. The CI comes with the database file cache, but according to the official statement, the cache will never expire unless you invoke the method to delete it actively. Cache ...

  • 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.