Recently, I came into contact with codeigniter's open-source lightweight architecture, which integrates common classes and function functions in development. The cache Summary of codeigniter includes the following:
1. database cache
The database cache is mainly used for select queries.
// Turn on the cache Switch
$ This-> DB-> cache_on ();
$ Query1 = $ this-> DB-> query ("select * From mytable ");
// Disable the following query from being cached
$ This-> DB-> cache_off ();
$ Query2 = $ this-> DB-> query ("select * from members where member_id = '$ CURRENT_USER '");
// Enable cache again
$ This-> DB-> cache_on ();
$ Query3 = $ this-> DB-> query ("select * From another_table ");
In this way, query1 and query3 are cached in the file. The cache Path depends on your url, for example, example.com/index.php/blog/commentspage, the cache system puts all generated cache files in a folder named "blog + Comments. if you want to delete the cache file corresponding to this example, You need to execute the following code:
$ This-> DB-> cache_delete ('blog ', 'comments'); // $ this-> DB-> cache_delete ('blog', 'comments ') # To delete the cache
To clear all database caches:
$this->db->cache_delete_all();
* The cache mode generates cache files for different Uris. If the parameters in the URL are different, the cache files are different, resulting in a vulnerability. If a visitor builds an automatic Uri and continuously initiates requests to the server, a large amount of junk files will be generated instantly, resulting in a bloated system file.
2. Page Cache
$ This-> output-> cache (n); // ensure that the application/cache is writable.
N is the number of minutes you want to cache updates. You can use M/60 to get accurate to the second. For example, 1/60 is accurate to 1 second.
3. Sequential cache to files
$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
if ( ! $foo = $this->cache->get('foo'))
{
echo 'Saving to the cache!<br />';
$foo = 'foobarbaz!';
// Save into the cache for 5 minutes
$this->cache->save('foo', $foo, 300);
}
echo $foo;
Additional reading: http://codeigniter.org.cn/user_guide/drivers/caching.html
Http://justcoding.iteye.com/blog/657357