开发者社区> 问答> 正文

关于php中smary的简单问题

$smarty = new Smarty;

$smarty->force_compile = true;
$smarty->debugging = true;
$smarty->caching = true;
$smarty->cache_lifetime = 120;
if(!$smarty->isCached('index.tpl')){
echo 'no cache';

} else {
echo 'cache';
}
$smarty->display('index.tpl');

请教一下,为什么我这样设置每次都是 no cache.
在我的cache目录下己经生成了缓存文件。

展开
收起
小旋风柴进 2016-03-06 11:51:53 2450 0
1 条回答
写回答
取消 提交回答
  • 此函数仅在 $caching设置为Smarty::CACHING_LIFETIME_CURRENTSmarty::CACHING_LIFETIME_SAVED的时候启用。 参见 缓存。

    <?php
    $smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
    
    if(!$smarty->isCached('index.tpl')) {
    // do database calls, assign vars here
    }
    
    $smarty->display('index.tpl');
    ?>
    2019-07-17 18:54:21
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
阿里云栖开发者沙龙PHP技术专场-深入浅出网络编程与swoole内核-吴镇宇 立即下载
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载