CodeIgniter Database Cache automatic Expiration processing method

Source: Internet
Author: User
Tags php framework codeigniter
This paper introduces the method of the automatic expiration of the CodeIgniter database cache, modifies the DB class, sets an expiration time when the cache is turned on, and the expiration auto-cache automatically expires.

CodeIgniter Database Cache Auto-expiration

The CodeIgniter framework is a very compact PHP framework that has been used in several recent projects. The CI comes with the database file cache, but according to the official statement, the cache will never expire after the set up, you invoke the method to delete actively.

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

Modified the DB class to set an expiration time when caching is turned on, and automatic expiration of expired auto-cache.

1, CI database/db_dirver.php 1021 lines cache_on function replaced by

function cache_on ($expire _time=0)//add parm expire time-cache expiration {$this->cache_expire_time = $expire _time;//add by Ken vin$this->cache_on = True;return TRUE;}

2, CI database/db_cache.php 90 line read function if (FALSE = = = ($cachedata = Read_file ($filepath))) line preceded by a

Determine whether to expire//Cache_expire_timeif (!file_exists ($filepath)) {return false;}//Bbs.it-home.orgif ($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 (); Modified to: $this →db→cache_on ($SEC); The $SEC is the cache expiration time, in seconds. For example, $this →db→cache_on (60); Indicates that the cache expires after 60 seconds.

  • Related Article

    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.