1.要使用缓存,首先要启用缓存
<?php
require("Smarty.class.php");
$smarty = new Smarty;
$smarty->caching = 1;
$smarty->display("index.htm");
?>
$smarty->caching有三个值
0/false:表示不使用缓存,每次都重新生成
1/true:使用当前的$cache_lifetime变量来判断缓存的生命期
2:当$complie_check = true时,缓存的生命期被修改,即任何的模板文件或配置文件中被修改的生命期
生命期即$cache_lifetime默认是3600秒(以秒为单位)
2.修改缓存全局生命期
<?php
require("Smarty.class.php");
$smarty = new Smarty;
$smarty->caching = 1;
$smarty->cache_lifetime=1800;
$smarty->display("index.htm");
?>
3.分别控制每个模板的缓存生命期
<?php
require("Smarty.class.php");
$smarty = new Smarty;
$smarty->caching = 2;
$smarty->cache_lifetime=1200;
$smarty->display("index.htm");
?>
4.$smarty->is_cached("index.htm",$cache_id);
检查该模板对应的$cache_id这个版本是否已经被缓存
5.$smarty->display("index.htm",$_GET['cache_id']);
获取名为$_GET['cache_id']的index.htm缓存版本
如果还不存在这个缓存,则用这个名字来缓存该模板实例
已实践:F:\xampp\htdocs\php100\smarty/test_foreach.php和test_if.php
分别使用了不同的缓存生命期
问题:我建了一个模板文件和一个对应的php文件,可是,我现在都删除了,但运行index文件时会有警告,提示我已经删了的文件不存在,怎么样才可以删除彻底?