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');