看看这个
require('Smarty.class.php');
$smarty = new Smarty;$smarty->caching = true;$my_cache_id = $_GET['article_id'];if(!$smarty->is_cached('index.tpl',$my_cache_id)) {
// No cache available, do variable assignments here.
$contents = get_database_contents();
$smarty->assign($contents);
}$smarty->display('index.tpl',$my_cache_id);
require('Smarty.class.php');
$smarty = new Smarty;$smarty->caching = true;$my_cache_id = $_GET['article_id'];if(!$smarty->is_cached('index.tpl',$my_cache_id)) {
// No cache available, do variable assignments here.
$contents = get_database_contents();
$smarty->assign($contents);
}$smarty->display('index.tpl',$my_cache_id);
这里就是定义这个cache的内容再什么情况下,视为无效,换句话讲,什么情况下需要重新cache,这里定义的就是:
当$my_cache_id变化时,cache无效.也就是讲,当有不同的$_GET['article_id']时,需要重新cache
传递附带的变量就可以了。