Smarty template partial caching method usage example_PHP tutorial

WBOY
Release: 2016-07-13 10:24:41
Original
734 people have browsed it

When smarty cache is turned on, the compiled output file will be saved in the cache directory when executed for the first time, and then in the program, the is_cache() function of smarty will be used to detect whether the cache file has expired. If it has expired, The cache will be updated, and if it has not expired, the cache file will be automatically called, thus eliminating the compilation process. Detecting cache expiration is to see whether the template file has changed within the specified life cycle. The change here is achieved by detecting the latest modification time of the file, not by detecting the content of the template file.


Prevent the entire template file from being cached:

index.php file:

Copy code The code is as follows:
require('smarty.class.php');
$smarty = new smarty;
$smarty->caching = true;

function smarty_block_dynamic($param, $content, &$smarty) {
return $content;
}
$smarty->register_block('dynamic', 'smarty_block_dynamic', false);

$smarty->display('index.tpl');


index.tpl:

Copy code The code is as follows:
page created: {"0"|date_format:"%d %h:%m:%s "}

{dynamic}

now is: {"0"|date_format:"%d %h:%m:%s"}

... do other stuff ...


{/dynamic}

When reloading this page, you will notice that the two dates are different. One is "dynamic" and the other is "static". You can do anything between {dynamic}...{/dynamic} and be sure it won't be cached like the rest of the page.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825342.htmlTechArticleWhen smarty caching is turned on, the compiled output file will be saved to the cache the first time it is executed. directory, and then detect its cache file through smarty's is_cache() function in the program...
Related labels:
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