Smarty Template Local Cache method Use example _php tutorial

Source: Internet
Author: User
In the case of the Smarty cache, the first execution will save its compiled output file to the cache directory, and then in the program through the Smarty Is_cache () function to detect whether its cache file expires, if the expiration will update the cache, If there is no expiration, the cache file is called automatically, thus eliminating the process of compiling. Detecting cache expiration is to see if the template file has changed over the specified life cycle, where the change was achieved by detecting the file's last modified time, not by detecting the template file contents.


Prevents the entire text of a template file from being cached:

index.php file:

Copy the Code code 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 the Code Code as follows: Page created: {"0" |date_format: "%d%h:%m:%s"}

{Dynamic}

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

... does other stuff ...


{/dynamic}

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

http://www.bkjia.com/PHPjc/825342.html www.bkjia.com true http://www.bkjia.com/PHPjc/825342.html techarticle when the Smarty cache is turned on, the first execution will save its compiled output file to the cache directory and then detect its cache file in the program through the Smarty Is_cache () function ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.