Example 14-2. setting cache_lifetime per cache
例14-2 設置單個緩存會話期〔時間〕
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching = 2; // lifetime is per cache
// set the cache_lifetime for index.tpl to 5 minutes
$smarty->cache_lifetime = 300;
$smarty->display('index.tpl');
// set the cache_lifetime for home.tpl to 1 hour
$smarty->cache_lifetime = 3600;
$smarty->display('home.tpl');
// NOTE: the following $cache_lifetime setting will not work when $caching = 2.
//提示:在$chching=2後麵的$chche_lifetime不會起作用。
// The cache lifetime for home.tpl has already been set
// to 1 hour, and will no longer respect the value of $cache_lifetime.
// home.tpl的緩存會話期設為1小時後,不會再按$cache_lifetime的值改變。
// The home.tpl cache will still expire after 1 hour.
// home.tpl的緩存會在1小時後結束。$smarty->cache_lifetime = 30; // 30 seconds
$smarty->display('home.tpl');
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching = true;
// clear out all cache files
$smarty->clear_all_cache();
// clear only cache for index.tpl
$smarty->clear_cache('index.tpl');
$smarty->display('index.tpl');