Cache Groups
You can do more elaborate grouping by setting up cache_id groups. This is accomplished by separating each sub-group with a vertical bar "|" in the cache_id value. You can have as many sub-groups as you like. Example 14-9. cache_id groupsrequire('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");// 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");
 
 

解决方案 »

  1.   

    哈哈,这段在网上下载的以前的中文手册里有,但没详细解说,我昨天愣是没看明白这个缓存组是怎么回事。今天过来看到二楼的回贴,认真再翻译理解下,并实验成功。
    马上到smarty官网下载了最新版的手册,就是没有中文版的呀,蛮看看了,这里解释比那个早期版本的中文手册详细多了,比较容易看明白了。呵!Cache Groups
    You can do more elaborate grouping by setting up $cache_id groups. This is accomplished by separating each sub-group with a vertical bar | in the $cache_id value. You can have as many sub-groups as you like. 
    You can think of cache groups like a directory hierarchy. For instance, a cache group of 'a|b|c' could be thought of as the directory structure '/a/b/c/'. clear_cache(null,'a|b|c') would be like removing the files '/a/b/c/*'. clear_cache(null,'a|b') would be like removing the files '/a/b/*'. If you specify a $compile_id such as clear_cache(null,'a|b','foo') it is treated as an appended cache group '/a/b/c/foo/'. If you specify a template name such as clear_cache('foo.tpl','a|b|c') then Smarty will attempt to remove '/a/b/c/foo.tpl'. You CANNOT remove a specified template name under multiple cache groups such as '/a/b/*/foo.tpl', the cache grouping works left-to-right ONLY. You will need to group your templates under a single cache group heirarchy to be able to clear them as a group. Cache grouping should not be confused with your template directory heirarchy, the cache grouping has no knowledge of how your templates are structured. So for example, if you have a template structure like themes/blue/index.tpl and you want to be able to clear all the cache files for the "blue" theme, you will need to create a cache group structure that mimics your template file structure, such as display('themes/blue/index.tpl','themes|blue'), then clear them with clear_cache(null,'themes|blue'). Example 14-9. $cache_id groups<?php
    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');// 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');// clear the foo.tpl cache file with "sports|basketball" as the cache_id
    $smarty->clear_cache('foo.tpl','sports|basketball');
    $smarty->display('index.tpl','sports|basketball');
    ?>  
     
    就是在缓存页面的时候像这样:
    $smarty->display('basic.tpl',"groupxxx|".$cache_id);然后要清这个groupxxx组下的所有缓存,则像这样:
    $smarty->clear_cache(null,"groupxxx");搞定!:)
    虽然给的答案我昨天早已看过,并没有详细说明,只是摘自手册,但还是给分吧。非常感谢!