background image

PHP 教程:smarty 缓存控制前的页面静态化原理

在配置文件中我们应设置了缓存的目录,但是缓存的只有一个文件,怎么让一个模版有
多个缓存文件呢
可在 display

 

中进行设置

$smarty->display("demo.tpl",$_SERVER[REQUEST_URI])

 

来实现一个模版有多个缓存。

既然文件已经有缓存了,我们就可以走缓存文件了,不用循环的执行连接数据库,进行
查询了。用 smatry

 

中的一个函数进行判断

$smarty->iscached(demo.tpl"",",$_SERVER[REQUEST_URI])

默认值为 true“ 这里的模版要

和 display

 

的一样。

在 smarty3 和在 smarty2

 

中是有区别的

$smarty->is_cached(demo.tpl"",",$_SERVER[REQUEST_URI]) smarty2 

$smarty->iscached(demo.tpl"",",$_SERVER[REQUEST_UR]I) smarty3 

但是在模版中有部分是不需要进行缓存的例如:用户的登录,和文章的评论部分就不需

 

要缓存的,那么我们这样解决

1,在 php

 

文件里,如果不需要缓存的数据 要放到 iscached

 

判断之外。

2.在模版中如果不需要缓存的部分就放到<{nocache}>........<{/nocache}>之间。