?
This document uses PHP Chinese website manual Release
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個參數(shù)就是$ cacheable , 并且它的值默認(rèn)為true。當(dāng)然,在2.6.0版本之前它的默認(rèn)值也是這樣的。
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.
當(dāng)用$cacheable=false來這冊一個插件,則每次這個頁面被輸出的時候,這個插件就會被使用,即使這個頁面來自緩存。這個插件函數(shù)的行為有點像這個函數(shù)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}相反,插件的屬性默認(rèn)是不緩存的。通過使用第四個參數(shù) $cache_attrs ,它們能夠被重新聲明為緩存的。 $cache_attrs 是一個屬性名字的數(shù)組,可以被緩存,所以每次當(dāng)它被從緩存中取出的時候,這個插件函數(shù)獲得值-----因為這個頁面會被寫入用來緩存。
Example 14-10. Preventing a plugin's output from being cached 例14-10.阻止插件從緩存中輸出
The number of seconds till the endtime of $obj is reached changes on each display of the page, even if the page is cached. Since the endtime attribute is cached the object only has to be pulled from the database when page is written to the cache but not on subsequent requests of the page. 直到$obj運(yùn)行結(jié)束,時間的秒數(shù)在每一個頁面輸出的時候會改變,即使這個頁面被緩存。只要結(jié)束時間屬性被緩存,當(dāng)頁面被寫入到緩存但是沒有對這個頁面接著的請求的時候?qū)ο笾皇遣坏貌恢匦聫臄?shù)據(jù)庫里取出而已。 ? |
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.
當(dāng)重新加載這個頁面,你將會注意到這兩個日期不同。一個是“動態(tài)“,一個是“靜態(tài)”。你能夠在{dynamic}...{/dynamic}之間作任何事情,并且保證它將不會像剩下的頁面一樣被緩存。