Smarty快取集合


Cache Groups [快取集合]

你可以通過建立cache_id集合做更祥細的集合體。在cache_id的值裡用豎線"|"來分開子集合。你可以盡可能多的包含子集合。 


Example 14-9. cache_id groups
例14-9.cache_id集合

require('Smarty.class.php');
$smarty = new Smarty;

$smarty->caching = true;

// clear all caches with "sports|basketball" as the first two cache_id groups
$smarty->clear_cache(null,"sports|basketball");
// www.tw511.com/smarty
// clear all caches with "sports" as the first cache_id group. This would
// include "sports|basketball", or "sports|(anything)|(anything)|(anything)|..."
$smarty->clear_cache(null,"sports");

$smarty->display('index.tpl',"sports|basketball");


技術提示:快取集合並不像cache_id一樣對模板使用路徑。比如,如果你display('themes/blue/index.tpl'),那麼在"themes/blue"目錄下你並不能清除快取。想要清除快取,必須先用cache_id把快取集合,像這樣display('themes/blue/index.tpl','themes|blue');然後就可以用clear_cache(null,'themes|blue')清除blue theme(藍色主題?!老外也真會叫...)下的快取。