?
Ce document utilise Manuel du site Web PHP chinois Libérer
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插件以來,如果注冊(cè)它們,則插件的緩存能力能夠被重新聲明的。register_block,register_compiler_function 和register_function的第3個(gè)參數(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來這冊(cè)一個(gè)插件,則每次這個(gè)頁面被輸出的時(shí)候,這個(gè)插件就會(huì)被使用,即使這個(gè)頁面來自緩存。這個(gè)插件函數(shù)的行為有點(diǎn)像這個(gè)函數(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)是不緩存的。通過使用第四個(gè)參數(shù) $cache_attrs ,它們能夠被重新聲明為緩存的。 $cache_attrs 是一個(gè)屬性名字的數(shù)組,可以被緩存,所以每次當(dāng)它被從緩存中取出的時(shí)候,這個(gè)插件函數(shù)獲得值-----因?yàn)檫@個(gè)頁面會(huì)被寫入用來緩存。
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í)間的秒數(shù)在每一個(gè)頁面輸出的時(shí)候會(huì)改變,即使這個(gè)頁面被緩存。只要結(jié)束時(shí)間屬性被緩存,當(dāng)頁面被寫入到緩存但是沒有對(duì)這個(gè)頁面接著的請(qǐng)求的時(shí)候?qū)ο笾皇遣坏貌恢匦聫臄?shù)據(jù)庫里取出而已。 ? |
Example 14-11. Preventing a whole passage of a template from being cached 例14-11.阻止一個(gè)模板文件的 整篇被緩存
|
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)重新加載這個(gè)頁面,你將會(huì)注意到這兩個(gè)日期不同。一個(gè)是“動(dòng)態(tài)“,一個(gè)是“靜態(tài)”。你能夠在{dynamic}...{/dynamic}之間作任何事情,并且保證它將不會(huì)像剩下的頁面一樣被緩存。