samrty解决局部不缓存的三种办法

当实时性要求比较高的时候(例如登录:欢迎。。。。登录)

   解决的办法:局部不缓存;

1、第一种方法:

1)、指定该函数的名称:nocache

2)、在插件目录下(plugins)创建一个块  命名为:block.nocache.php

      该函数中的内容:

<?php

       function smarty_block_nocache($args,$content){

              return$content;

}

?>

 

*.Php

$tpl->assign(“data”.date(“H:i:s”));

 

*.tpl

<{nocache}><{$data}><{/nocache}>

 

写成插件时,要配置Smarty_Compiler.class.php  让函数为:nocache的当执行它的时候不被缓存; 操作如下:文件名:  Smarty_Compiler.class.php 

行数:  713---719 

针对smarty版本:   3.1.4

       

       if($tag_command==nocache){

                   $this->_plugins['block'][$tag_command]= array($plugin_func, null, null, null, false);

            }

            else {

               $this->_plugins['block'][$tag_command] = array($plugin_func, null,null, null, true);

 

            }

 

 

第二种:写在php文件中:

 

 

*.php

$tpl->register_block("nocache","fun1",false);  false代表当执行该块时是不被缓存的。

 

function fun1($args,$content){ return $content; }

 

$tpl->assign("time",date("H:i:s"));

 

*.tpl

<{nocache}><{$time}><{/nocache}>

 

 

 

第三种:smarty内建函数insert:

*.php

       function insert_fun1(){return date(“H:i:s”); }

       注意:用内建函数insert时,函数名都要加上insert_你要定义的函数名

*.tpl

       <insert name=”fun1”>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值