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.