smarty缓存的应用

来源:互联网 发布:bizhub7622 连接端口 编辑:程序博客网 时间:2024/09/21 09:02
 

1、Smarty缓存的配置,这些内容要加到配置文件中

$smarty->cache_dir = "/caches/";  //缓存目录

$smarty->caching = true;  //开启缓存,为flase的时侯缓存无效

$smarty->cache_lifetime = 60;  //缓存时间

2、Smarty缓存的使用和清除

$smarty->display('cache.tpl', cache_id);  //创建带ID的缓存

$smarty->clear_all_cache(); //清除所有缓存

$smarty->clear_cache('index.htm'); //清除index.tpl的缓存

$smarty->clear_cache('index.htm',cache_id); //清除指定id的缓存

3、Smarty局部缓存

insert 函数默认是不缓存的。并且这个属性不能修改。

index.htm

<div>{insert name="get_time"}</div>

index.php

function insert_get_time(){

return date("Y-m-d H:m:s");

smarty_block 函数功能更加强大,使用方法同上

{blockname}

没有缓存的:{$smarty.now}

{/blockname}

 

原创粉丝点击