您当前的位置:首页 > 分类 > 技术资讯 > Smarty > 正文

Smarty 缓存集合

发布时间:2016-08-05 14:14:34      来源:51推一把
【摘要】Cache Groups你可以通过建立cache_id集合做更祥细的集合体。在cache_id的值里用竖线"|"来分开子集合。你可以尽可能多的包含子集合。
Cache Groups [缓存集合]
你可以通过建立cache_id集合做更祥细的集合体。在cache_id的值里用竖线"|"来分开子集合。你可以尽可能多的包含子集合。

#cache_id集合
require(Smarty.class.php);
$smarty = new Smarty;
$smarty->caching = true;
// clear all caches with "sports|basketball" as the first two cache_id groups
$smarty->clear_cache(null,"sports|basketball");
// www.yiibai.com/smarty
// clear all caches with "sports" as the first cache_id group. This would
// include "sports|basketball", or "sports|(anything)|(anything)|(anything)|..."
$smarty->clear_cache(null,"sports");

$smarty->display(index.tpl,"sports|basketball");

技术提示:缓存集合并不像cache_id一样对模板使用路径。比如,如果你display(themes/blue/index.tpl),那么在"themes/blue"目录下你并不能清除缓存。想要清除缓存,必须先用cache_id把缓存集合,像这样display(themes/blue/index.tpl,themes|blue);然后就可以用clear_cache(null,themes|blue)清除blue theme(蓝色主题?!老外也真会叫...)下的缓存。