1、Smarty缓存的配置
$smarty->cache_dir = "/caches/"; //缓存目录
$smarty->caching = true; //开启缓存,为flase的时侯缓存无效
$smarty->cache_lifetime = 60; //缓存时间
$smarty->display('color.tpl', "cacheid|color1");
$smarty->display('color.tpl', "cacheid|color2");
$smarty->caching = true; //开启缓存,为flase的时侯缓存无效
$smarty->cache_lifetime = 60; //缓存时间
$smarty->display('color.tpl', "cacheid|color1");
$smarty->display('color.tpl', "cacheid|color2");
2、 Smarty缓存的使用和清除
<?php
require("libs/smarty.class.php");
$smarty = new Smarty();
//$smarty->clear_all_cache(); //清除所有的缓存
//$smarty->clear_cache('color.tpl'); //清除不带cacheid的页面缓存
//$smarty->clear_cache('color.tpl',"cacheid|color1"); //清除
//$smarty->clear_cache('color.tpl',"cacheid|color2"); //清除
$smarty->clear_cache(null,"cacheid"); 一次性清除页面中所有cacheid缓存
?>
require("libs/smarty.class.php");
$smarty = new Smarty();
//$smarty->clear_all_cache(); //清除所有的缓存
//$smarty->clear_cache('color.tpl'); //清除不带cacheid的页面缓存
//$smarty->clear_cache('color.tpl',"cacheid|color1"); //清除
//$smarty->clear_cache('color.tpl',"cacheid|color2"); //清除
$smarty->clear_cache(null,"cacheid"); 一次性清除页面中所有cacheid缓存
?>
3.is_cached
<?
if(!$smarty->is_cached('color.tpl',"cacheid|color1")) {
$smarty->assign("content", date("Y-m-d H:i:s"));
}else{
}
?>
$smarty->assign("content", date("Y-m-d H:i:s"));
}else{
}
?>