什么是缓存
缓存能够非常有效的缓解网站的压力
smarty缓存分为三种,全局缓存,部分缓存,局部缓存
全局缓存是指一个页面会根据get的id生成不同的缓存文件,是指一个页面可以生成多个缓存文件
$smarty->display(模版文件,缓存id);
根据display的第二个参数生成不同的缓存文件
部分缓存实质上是指部分不缓存,是指一个页面不生成缓存文件
$smarty->display(模版文件) display不写第二个参数
具体方法是使用$smarty->cache_clear(模版文件)
局部缓存是指一个页面的一些内容不生成缓存文件,比如时间不能生成缓存,应该实时更新,格式
function insert_timeget(){
return time();
}
模版文件
{insert name=”timeget”}
smarty引擎怎么生成静态页面
使用$smarty->Fetch(“模版名”);
这个方法捕获文件里面的html部分
代码
$path=”./static/index.html”;
If(is_file($path){
Include_once($path);
}
$data=$smarty->Fetch(‘cache2.html’);
file_put_contents($path,$data);
浙公网安备 33010602011771号