When the smarty cache is enabled, the compiled output file will be saved to the cache directory during the first execution, and then passed the smarty is_cache () the function checks whether the cache file has expired. 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:
Copy codeThe 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 codeCode: 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.