Current position: home page > Website Design >The emlog template adds a data cache to the custom list (read list acceleration effect)

The emlog template adds a data cache to the custom list (read list acceleration effect)

Author: blueleaf Classification: Website Design Time: December 23, 2023 Browse: 386

stay Emlog template Sometimes, we need to display some custom lists, such as article categories, tag clouds, friendship links, etc. These lists usually obtain data from the database and Template The engine renders the displayed. However, for some frequently updated lists, getting data from the database and rendering each time may affect performance. To solve this problem, we can consider adding the data cache function in the template.

 Add data cache.png to the user-defined list in the emlog template

Here is a complete Emlog template The code function that adds data cache to the custom list in can be directly copied to emlog Module in the template folder php File, and then write the calling code at the required location of the emlog template to accelerate the reading list of the emlog template.

 <? php //Read article list write cache //Call method: lanye_Listcache ('1,2,3 ','20', 'listcache'); //There are three parameters. The first is the classification ID, the second is the number of reads, and the third is the cache file name function lanye_Listcache($sortid = 0, $lognum = '10', $cachename = 'listcache'){ global $CACHE; $db = Database::getInstance(); if($sortid){$query = "and sortid in ($sortid)";}else{$query = '';} $sql = "select * from ". DB_PREFIX."blog WHERE type='blog' and hide='n' and checked='y' $query ORDER BY `date` DESC LIMIT 0,$lognum"; $listcache = $CACHE->readCache($cachename); if(empty($listcache)){ $list = $db->query($sql); $listcache = array(); while($row = $db->fetch_array($list)){ $listcache[] = $row; echo '<li><a href="'. Url::log($row['gid']).' " title="'.$ row['title'].' " target="_blank">'.$row['title'].'</a></li>'; } $cacheData = serialize($listcache); $CACHE->cacheWrite($cacheData, $cachename); }else{ foreach($listcache as $row){ echo '<li><a href="'. Url::log($row['gid']).' " title="'.$ row['title'].' " target="_blank">'.$row['title'].'</a></li>'; } } }

Disclaimer:

Website: Click Copy to share with friends!

All content resources shared by this website, if not noted, are original by Blueleaf. If you need to reprint, please indicate the source; Please contact us in case of infringement Contact handling Please understand!

Comment List
 blink the eyes kiss Growl happy think poor It's embarrassing Grievance ha-ha hush Right hum Zuo Hum Hum doubt A bad laugh Make money Sadness Be cool Seduce fierce handshake yeah Hee hee Shyness applause greedy Madness Embrace gather and watch Mighty awesome
Submit comments

Clear information
Close Comment
music appreciation
Back to top