教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php smarty模板局部缓存方法

php smarty模板局部缓存方法

发布时间:2023-05-11   编辑:jiaochengji.com
教程集为您提供php smarty模板局部缓存方法等资源,欢迎您收藏本站,我们将为您提供最新的php smarty模板局部缓存方法资源

如果开启smarty缓存,第一次执行时会将其编译好的输出文件保存到cache目录中,在程序中通过smarty的is_cache()函数检测其 cache文件是否过期,若过期会更新缓存,如果没有过期会自动调用cache文件,省去编译的过程。检测cache过期是看模板文件是否在指定的生命周期内是否更改,这里的更改是是通过检测文件的最近修改时间实现的,不是通过检测模板文件内容。
   阻止一个模板文件的 整篇被缓存 :

index.php教程:

require('smarty.class.php');
$smarty = new smarty;
$smarty->caching = true;

function smarty_block_dynamic($param, $content, &$smarty) {
return $content;
}
$smarty->register_block('dynamic', 'smarty_block_dynamic', false);

$smarty->display('index.tpl');


index.tpl:

page created: {"0"|date_format:"%d %h:%m:%s"}

{dynamic}

now is: {"0"|date_format:"%d %h:%m:%s"}

... do other stuff ...



{/dynamic}
当重新加载这个页面,你将会注意到这两个日期不同。一个是“动态“,一个是“静态”。你能够在{dynamic}...{/dynamic}之间作任何事情,并且保证它将不会像剩下的页面一样被缓存。

您可能感兴趣的文章:
PHP模板引擎Smarty缓存使用
php Smarty的缓存操作
有关smarty的基本设置
有关smarty缓存的应用
smarty获得当前url示例代码
有关smarty模板引擎生成静态页的关键代码
在php中配置使用smarty模板引擎
smarty 模板if else使用实例与入门教程
php模版生成html的小例子
用 Smarty 分离 PHP 应用程序中的形式与功能

[关闭]
~ ~