The CodeIgniter framework is a very small PHP framework. CI comes with the Database File Cache, but according to the official saying, the cache setting never expires, unless you call the 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 mentally retarded and inconvenient. Modify the db class and set an expiration time when cache is enabled. The cache automatically becomes invalid upon expiration.
1: replace 1021 rows of cache_on function in CI database/DB_dirver.php
Copy codeCode: 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: Add 90 rows of read function if (FALSE = ($ cachedata = read_file ($ filepath) in CI database/DB_cache.php
Copy codeThe Code is as follows: // determine whether the expiration date exists. // 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, change from $ this → db → cache_on ();
Copy codeThe Code is as follows: $ this → db → cache_on ($ SEC );
$ SEC indicates the cache expiration time, in seconds. For example, $ this → db → cache_on (60); indicates that the cache expires 60 seconds later.