当前位置:博客首页>>PHP >> 阅读正文

学习smarty第三天-smarty缓存机制入门

作者: 郑晓 分类: PHP 发布于: 2011-11-24 23:31 浏览:4,649 没有评论


1. smarty缓存的配置:

$smarty->caching = true;  // 开启smarty缓存机制

$smarty->cache_dir = “/cache/”;   // 设置缓存文件保存目录

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

2.smarty缓存的使用及清除:

$smarty->display(“index.htm”,cache_id); //第二参数可选,创建带id的缓存

$smarty->clear_all_cache(); //此函数将清除所有缓存

$smarty->clear_cache(“index.htm”,cache_id); //清除指定id的缓存(同时会删除index.htm的缓存)

3.smarty的局部缓存应用:

insert中默认不进行缓存。

模板文件中用insert来调用name标记的不缓存变量:

{insert name=”name”}

php中使用insert前缀方法:

function insert_name(){

return $xxx;

}

不需要用assign()引入。

smarty_block:
php中 建立 function smarty_block_names(){
return $xxx;
}
注册:
$smarty->register_block(“names”,”smarty_block_names”,false); // false 是表示不进行缓存
模板中:{names}此处变量不被缓存{$names}{/names}

       

本文采用知识共享署名-非商业性使用 3.0 中国大陆许可协议进行许可,转载时请注明出处及相应链接。

本文永久链接: https://www.zh30.com/smarty-huancun-3.html

发表评论

change vcode