在開啟smarty緩衝的情況下,第一次執行時會將其編譯好的輸出檔案儲存到cache目錄中,然後在程式中通過smarty的is_cache()函數檢測其 cache檔案是否到期,如果到期會更新緩衝,如果沒有到期會自動調用cache檔案,這樣就省去了編譯的過程。檢測cache到期是看模板檔案是否在指定的生命週期內是否更改,這裡的更改是通過檢測檔案的最近修改時間實現的,不是通過檢測模板檔案內容。
防止一個模板檔案的整篇都被緩衝:
index.php檔案:
複製代碼 代碼如下: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:
複製代碼 代碼如下:page created: {"0"|date_format:"%d %h:%m:%s"}
{dynamic}
now is: {"0"|date_format:"%d %h:%m:%s"}
... do other stuff ...
{/dynamic}
當重新載入這個頁面,你將會注意到這兩個日期不同。一個是“動態“,一個是“靜態”。你能夠在{dynamic}...{/dynamic}之間作任何事情,並且保證它將不會像剩下的頁面一樣被緩衝。
http://www.bkjia.com/PHPjc/825342.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/825342.htmlTechArticle在開啟smarty緩衝的情況下,第一次執行時會將其編譯好的輸出檔案儲存到cache目錄中,然後在程式中通過smarty的is_cache()函數檢測其 cache檔案...