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