| 148 |
lars |
1 |
isCached()
|
|
|
2 |
|
|
|
3 |
returns true if there is a valid cache for this template
|
|
|
4 |
|
|
|
5 |
Description
|
|
|
6 |
===========
|
|
|
7 |
|
|
|
8 |
bool
|
|
|
9 |
|
|
|
10 |
isCached
|
|
|
11 |
|
|
|
12 |
string
|
|
|
13 |
|
|
|
14 |
template
|
|
|
15 |
|
|
|
16 |
string
|
|
|
17 |
|
|
|
18 |
cache\_id
|
|
|
19 |
|
|
|
20 |
string
|
|
|
21 |
|
|
|
22 |
compile\_id
|
|
|
23 |
|
|
|
24 |
- This only works if [`$caching`](#variable.caching) is set to one of
|
|
|
25 |
`Smarty::CACHING_LIFETIME_CURRENT` or
|
|
|
26 |
`Smarty::CACHING_LIFETIME_SAVED` to enable caching. See the [caching
|
|
|
27 |
section](#caching) for more info.
|
|
|
28 |
|
|
|
29 |
- You can also pass a `$cache_id` as an optional second parameter in
|
|
|
30 |
case you want [multiple caches](#caching.multiple.caches) for the
|
|
|
31 |
given template.
|
|
|
32 |
|
|
|
33 |
- You can supply a [`$compile id`](#variable.compile.id) as an
|
|
|
34 |
optional third parameter. If you omit that parameter the persistent
|
|
|
35 |
[`$compile_id`](#variable.compile.id) is used if its set.
|
|
|
36 |
|
|
|
37 |
- If you do not want to pass a `$cache_id` but want to pass a
|
|
|
38 |
[`$compile_id`](#variable.compile.id) you have to pass NULL as a
|
|
|
39 |
`$cache_id`.
|
|
|
40 |
|
|
|
41 |
> **Note**
|
|
|
42 |
>
|
|
|
43 |
> If `isCached()` returns TRUE it actually loads the cached output and
|
|
|
44 |
> stores it internally. Any subsequent call to
|
|
|
45 |
> [`display()`](#api.display) or [`fetch()`](#api.fetch) will return
|
|
|
46 |
> this internally stored output and does not try to reload the cache
|
|
|
47 |
> file. This prevents a race condition that may occur when a second
|
|
|
48 |
> process clears the cache between the calls to `isCached()` and to
|
|
|
49 |
> [`display()`](#api.display) in the example above. This also means
|
|
|
50 |
> calls to [`clearCache()`](#api.clear.cache) and other changes of the
|
|
|
51 |
> cache-settings may have no effect after `isCached()` returned TRUE.
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
<?php
|
|
|
55 |
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
|
|
|
56 |
|
|
|
57 |
if(!$smarty->isCached('index.tpl')) {
|
|
|
58 |
// do database calls, assign vars here
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
$smarty->display('index.tpl');
|
|
|
62 |
?>
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
<?php
|
|
|
68 |
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
|
|
|
69 |
|
|
|
70 |
if(!$smarty->isCached('index.tpl', 'FrontPage')) {
|
|
|
71 |
// do database calls, assign vars here
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
$smarty->display('index.tpl', 'FrontPage');
|
|
|
75 |
?>
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
See also [`clearCache()`](#api.clear.cache),
|
|
|
80 |
[`clearAllCache()`](#api.clear.all.cache), and [caching
|
|
|
81 |
section](#caching).
|