Everyone will ask what is cache! What can you do! In fact, cache is equivalent to memory. Save it for a while!
Caching means we don’t need to execute the database when executing things. Just execute our cache directly
Generally speaking, the purpose of caching is to put data in one place to make access faster. There is no doubt that memory is the fastest, but a few hundred M Can the data be stored in the internal memory? This is unrealistic. Of course, sometimes it is temporarily stored in the server cache. For example, if the ob_start() cache page is turned on, the page content will be cached in the memory before sending the file header until the page is output. Automatically clear or wait for the return of ob_get_contents, or be cleared by ob_end_clean display. This can be well used in the generation of static pages and can be well reflected in templates. This article of mine discusses it in depth: Talking about PHP Generating static pages is one way, but it is temporary and not a good way to solve our problem.
It can be said that caching is generally divided into page caching and data caching. ADODB cache is data cache. smarty is page cache. The adodb cache is
<?php }include(./adodb/adodb.inc.php); $ADODB_CACHE_DIR='tmp'; $db=NewADOConnect('mysql'); $db->connect('localhost','root','123456','mysql'); $sql="select * from user"; $db->cacheexecute(300,$sql); ?> Copy after login |
, so the cache is generated in the TMP directory! (The cache file is serialized data.) The next time it is executed, we read the data directly from the cache. SMARTY cache:
<?phprequire('./smarty/Smarty.class.php'); $smarty = new Smarty; Z)$smarty->caching = true;if(!$smarty->is_cached('index.tpl')) // No cache available, do variable assignments here. ) $contents = get_database_contents(); $smarty->assign($contents);} $smarty->display('index.tpl'); )?> Copy after login |
This first determines whether there is this cache file! There is no direct link to the database! If so! Execute DISPLAY. It's the read cache. Everyone saw the 2 examples above! Now you have a great understanding of caching!