| 148 |
lars |
1 |
Cache Groups {#caching.groups}
|
|
|
2 |
============
|
|
|
3 |
|
|
|
4 |
You can do more elaborate grouping by setting up `$cache_id` groups.
|
|
|
5 |
This is accomplished by separating each sub-group with a vertical bar
|
|
|
6 |
`|` in the `$cache_id` value. You can have as many sub-groups as you
|
|
|
7 |
like.
|
|
|
8 |
|
|
|
9 |
- You can think of cache groups like a directory hierarchy. For
|
|
|
10 |
instance, a cache group of `'a|b|c'` could be thought of as the
|
|
|
11 |
directory structure `'/a/b/c/'`.
|
|
|
12 |
|
|
|
13 |
- `clearCache(null,'a|b|c')` would be like removing the files
|
|
|
14 |
`'/a/b/c/*'`. `clearCache(null,'a|b')` would be like removing the
|
|
|
15 |
files `'/a/b/*'`.
|
|
|
16 |
|
|
|
17 |
- If you specify a [`$compile_id`](#variable.compile.id) such as
|
|
|
18 |
`clearCache(null,'a|b','foo')` it is treated as an appended cache
|
|
|
19 |
group `'/a/b/c/foo/'`.
|
|
|
20 |
|
|
|
21 |
- If you specify a template name such as
|
|
|
22 |
`clearCache('foo.tpl','a|b|c')` then Smarty will attempt to remove
|
|
|
23 |
`'/a/b/c/foo.tpl'`.
|
|
|
24 |
|
|
|
25 |
- You CANNOT remove a specified template name under multiple cache
|
|
|
26 |
groups such as `'/a/b/*/foo.tpl'`, the cache grouping works
|
|
|
27 |
left-to-right ONLY. You will need to group your templates under a
|
|
|
28 |
single cache group hierarchy to be able to clear them as a group.
|
|
|
29 |
|
|
|
30 |
Cache grouping should not be confused with your template directory
|
|
|
31 |
hierarchy, the cache grouping has no knowledge of how your templates are
|
|
|
32 |
structured. So for example, if you have a template structure like
|
|
|
33 |
`themes/blue/index.tpl` and you want to be able to clear all the cache
|
|
|
34 |
files for the "blue" theme, you will need to create a cache group
|
|
|
35 |
structure that mimics your template file structure, such as
|
|
|
36 |
`display('themes/blue/index.tpl','themes|blue')`, then clear them with
|
|
|
37 |
`clearCache(null,'themes|blue')`.
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
<?php
|
|
|
41 |
require('Smarty.class.php');
|
|
|
42 |
$smarty = new Smarty;
|
|
|
43 |
|
|
|
44 |
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
|
|
|
45 |
|
|
|
46 |
// clear all caches with 'sports|basketball' as the first two cache_id groups
|
|
|
47 |
$smarty->clearCache(null,'sports|basketball');
|
|
|
48 |
|
|
|
49 |
// clear all caches with "sports" as the first cache_id group. This would
|
|
|
50 |
// include "sports|basketball", or "sports|(anything)|(anything)|(anything)|..."
|
|
|
51 |
$smarty->clearCache(null,'sports');
|
|
|
52 |
|
|
|
53 |
// clear the foo.tpl cache file with "sports|basketball" as the cache_id
|
|
|
54 |
$smarty->clearCache('foo.tpl','sports|basketball');
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
$smarty->display('index.tpl','sports|basketball');
|
|
|
58 |
?>
|
|
|
59 |
|
|
|
60 |
|