Since Smarty-2.6.0 plugins the cacheability of plugins can be declared when registering them. The third parameter to register_block, register_compiler_function and register_function is called $cacheable and defaults to true which is also the behaviour of plugins in Smarty versions before 2.6.0
自从Smarty-2.6.0插件以来,如果注册它们,则插件的缓存能力能够被重新声明的。register_block,register_compiler_function 和register_function的第3个参数就是$ cacheable , 并且它的值默认为true。当然,在2.6.0版本之前它的默认值也是这样的。
When registering a plugin with $cacheable=false the plugin is called everytime the page is displayed, even if the page comes from the cache. The plugin function behaves a little like an insert function.
当用$cacheable=false来这册一个插件,则每次这个页面被输出的时候,这个插件就会被使用,即使这个页面来自缓存。这个插件函数的行为有点像这个函数insert。
In contrast to {insert} the attributes to the plugins are not cached by default. They can be declared to be cached with the fourth parameter $cache_attrs . $cache_attrs is an array of attribute-names that should be cached, so the plugin-function get value as it was the time the page was written to cache everytime it is fetched from the cache.
和{insert}相反,插件的属性默认是不缓存的。通过使用第四个参数 $cache_attrs ,它们能够被重新声明为缓存的。 $cache_attrs 是一个属性名字的数组,可以被缓存,所以每次当它被从缓存中取出的时候,这个插件函数获得值-----因为这个页面会被写入用来缓存。
Example 14-11. Preventing a whole passage of a template from being cached 例14-11.阻止一个模板文件的 整篇被缓存
|
When reloading the page you will notice that both dates differ. One is "dynamic" one is "static". You can do everything between {dynamic}...{/dynamic} and be sure it will not be cached like the rest of the page.
当重新加载这个页面,你将会注意到这两个日期不同。一个是“动态“,一个是“静态”。你能够在{dynamic}...{/dynamic}之间作任何事情,并且保证它将不会像剩下的页面一样被缓存。