欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

smarty模板局部緩存方法使用示例

 更新時間:2014年06月17日 17:18:35   投稿:shichen2014  
這篇文章主要介紹了smarty模板局部緩存方法,需要的朋友可以參考下

在開啟smarty緩存的情況下,第一次執(zhí)行時會將其編譯好的輸出文件保存到cache目錄中,然后在程序中通過smarty的is_cache()函數(shù)檢測其 cache文件是否過期,如果過期會更新緩存,如果沒有過期會自動調(diào)用cache文件,這樣就省去了編譯的過程。檢測cache過期是看模板文件是否在指定的生命周期內(nèi)是否更改,這里的更改是通過檢測文件的最近修改時間實現(xiàn)的,不是通過檢測模板文件內(nèi)容。


防止一個模板文件的整篇都被緩存:

index.php文件:

復(fù)制代碼 代碼如下:
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:

復(fù)制代碼 代碼如下:
page created: {"0"|date_format:"%d %h:%m:%s"}

{dynamic}

now is: {"0"|date_format:"%d %h:%m:%s"}

... do other stuff ...


{/dynamic}

當(dāng)重新加載這個頁面,你將會注意到這兩個日期不同。一個是“動態(tài)“,一個是“靜態(tài)”。你能夠在{dynamic}...{/dynamic}之間作任何事情,并且保證它將不會像剩下的頁面一樣被緩存。

相關(guān)文章

最新評論