是的,先确认SmartTemplate::cache_dir存在且可读写$tpl = new SmartTemplate("模板文件名");//这里是一些准备工作。通常user_cache方法是要传递一个唯一的标识的,这样才能识别需要读去的是哪个缓存。否则,只使用默认值''而缓存文件又存在的情况下,就不能达到你的目的了。$tpl->user_cache();//这里是数据加载。注意不可在此附加其他动作,因为一旦user_cache读取了缓存则终止程序的执行$tpl->output();
?>
?>
function use_cache ( $key = '' ){
if (empty($_POST)) {
$this->cache_filename = $this->cache_dir . 'cache_' . md5($_SERVER['REQUEST_URI'] . serialize($key)) . '.ser';
if (($_SERVER['HTTP_CACHE_CONTROL'] != 'no-cache') && ($_SERVER['HTTP_PRAGMA'] != 'no-cache') && @is_file($this->cache_filename)){
if ((time() - filemtime($this->cache_filename)) < $this->cache_lifetime){
readfile($this->cache_filename);
exit;
}
}
ob_start( array( &$this, 'cache_callback' ) );
}
}