缓存组

    通过设置$cache_id组,你可以完成更精密的分组。该方法是通过在$cache_id值中用“|”对每个子分组加以分割而实现的。你想要多少子分组就有多少。

    缓存分组不应与你的模板目录继承相混淆,缓存组根本不知道你的模板是什么结构。比如说,你有一个模板结构形如themes/blue/index.tpl,而你想要清除"blue"主题下所有的缓存文件,那么你应该创建一个缓存组结构来模拟你的模板文件结构,诸如display('themes/blue/index.tpl','themes|blue'),然后用clear_cache(null,'themes|blue')将它们加以清除。

例子14-9. $cache_id组

<?php
require('Smarty.class.php');
$smarty = new Smarty;

$smarty->caching true;

// 清除所有以'sports|basketball'作为头两个cache_id组的缓存
$smarty->clear_cache(null,'sports|basketball');

// 清除所有以"sports"作为第一个cache_id组的缓存。这将
// 包括"sports|basketball"或者"sports|(anything)|(anything)|(anything)|..."
$smarty->clear_cache(null,'sports');

// 清除foo.tpl的缓存文件,而其cache_id为"sports|basketball"
$smarty->clear_cache('foo.tpl','sports|basketball');


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