多个缓存:display('index.tpl')在多种条件下会有不同的输出内容,要单独的把缓存分开
传给display()一个cache_id
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching = true;
$cache_id = $_GET['article_id'];
$smarty->display('index.tpl',$cache_id);
注意article_id的长度是10字符,并只由字符-数字组成,在数据库里是个可用的article_id
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching = true;
$cache_id = $_GET['article_id'];
if(!$smarty->is_cached('index.tpl',$cache_id)) {//检查
$contents = get_database_contents();
$smarty->assign($contents);
}
$smarty->display('index.tpl',$cache_id)
可以把clear_cache()的第一参数设为null来为特定的cache_id清除所有缓存。
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching = true;
//清除cache_id为test的所有缓存
$smarty->clear_cache(null,"test");
$smarty->display('index.tpl',"test");
缓存集合:子集合用”|“隔开
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching = true;
//清除前两组test和test1所有缓存
$smarty->clear_cache(null,"test|test1");
//清除test数组的所有缓存
$smarty->clear_cache(null,"test");
$smarty->display('index.tpl',"test|test1");