How to use the smarty template partial cache method _ PHP

Source: Internet
Author: User
Tags smarty template
This article mainly introduces the local cache method of the smarty template. For more information, see enable the smarty cache, during the first execution, the compiled output file will be saved to the cache Directory. Then, in the program, the smarty is_cache () function is used to check whether the cache file expires. If it expires, the cache will be updated, if it does not expire, the cache file will be automatically called, saving the compilation process. Check whether the template file is changed within the specified lifecycle. the changes here are implemented by checking the latest modification time of the file, not the template file content.


To prevent the entire template file from being cached:

Index. php file:

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:

Code: page created: {"0" | date_format: "% d % h: % m: % s "}

{Dynamic}

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

... Do other stuff...


{/Dynamic}

When you reload the 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 ensure that it will not be cached like the rest of the page.

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

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.