Home > Backend Development > PHP Tutorial > PHP caching in detail_PHP tutorial

PHP caching in detail_PHP tutorial

WBOY
Release: 2016-07-15 13:25:21
Original
794 people have browsed it

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!


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446694.htmlTechArticleEveryone will ask what is cache! What can you do! In fact, cache is equivalent to memory. Save it for a while! Caching means that we don’t need to execute the database when executing things. Directly execute our...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template