This example describes the use of Yii database caching. Share to everyone for your reference, specific as follows:
Yii Operations Database Cache:
1, in the main.php main file to add
' Dbcache ' =>array (
' class ' => ' System.caching.CDbCache ',
//database caching, pay attention to your own path issues
),
2, set up the database cache
Yii::app ()->cache->set ($key, $value, $outtime);
$key a unique primary key, $value the value of the corresponding primary key (which can be an array), $outtime the expiration time.
3. Get Cache
Yii::app ()->cache->get ($key);
Primary key keys when setting the database cache
4. Delete Cache
Yii::app ()->cache->delete ($key);/ibid.
5, empty the cache file
Yii::app ()->cache->fulsh ();
All file caches above the server will be deleted, that is, all cached files in the cache folder
Application Example: (A lot of video is not given in the list page if you do caching, the list page needs to have page information, slightly more complex, the following gives a list page of the database Cache instance)
Current URL address: http://www.aaaa.com/news/list/gid/2/nid/3/page/1.html
First determine if the cache exists:
if (isset ($_get[' gid ')) {
$gid = intval ($_get[' gid '));
else{
$gid = 1;
}
..........
I have omitted the other judgment condition here, the information that only needs to decide now has $gid, $nid, $pages (note, the current variable does not use $page but use $pages, because if use $page error, and paging $page conflict)
$newsListCache = Yii::app ()->cache->get ("Newslist$gid$nid$pages");
can guarantee its uniqueness can be
if (!empty ($newsListCache))//To determine if there is this file to go under this file return, so the following data will not go back to
$newsListCache;
。。 Here is your other code data, don't worry about it
Yii::app ()->cache->set ("Newslist$gid$nid$pages", $newsList, 3600); The first parameter here needs to correspond to the above, the second parameter is your data, and the third parameter is the expiration time.
More about Yii related content readers can view the site topics: "Yii framework Introduction and common skills Summary", "PHP Excellent Development Framework Summary", "Smarty Template Primer Tutorial", "PHP date and Time usage summary", "PHP object-oriented Programming Program", " Summary of PHP string usage, Introduction to PHP+MYSQL database operations, and a summary of PHP common database operations Tips
I hope this article will help you with your PHP programming based on the YII framework.