|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
FalconIA Smarty n00b
Joined: 11 Jan 2012 Posts: 3
|
Posted: Wed Jan 11, 2012 10:31 pm Post subject: CacheLifetime problem |
|
|
In 'Smarty::CACHING_LIFETIME_SAVED' mode.
If call 'isCached()' before 'setCacheLifetime()', the 'cache_lifetime' does't change any more.
e.g.
Code: | $smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED);
$smarty->setCacheLifetime(0);
if ($smarty->isCached($template, $cache_id)) {
// ...
}
$smarty->setCacheLifetime(300); // No use at all
$smarty->display($template, $cache_id); |
I test it in 3 versions of smarty.
3.0.5 => works well, there's no problem
3.0.7 => 'cache_lifetime' is locked after 'isCached()' called
3.1.7 => 'cache_lifetime' is locked after 'isCached()' called |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Thu Jan 12, 2012 9:46 am Post subject: |
|
|
Try this:
Code: | $smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED);
$smarty->setCacheLifetime(0);
$tpl = $smarty->createTemplate($template, $cache_id);
if ($tpl->isCached()) {
// ...
}
$tpl->setCacheLifetime(300);
$tpl->display(); |
_________________ Twitter |
|
Back to top |
|
FalconIA Smarty n00b
Joined: 11 Jan 2012 Posts: 3
|
Posted: Thu Jan 12, 2012 6:24 pm Post subject: |
|
|
rodneyrehm wrote: | Try this:
Code: | $smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED);
$smarty->setCacheLifetime(0);
$tpl = $smarty->createTemplate($template, $cache_id);
if ($tpl->isCached()) {
// ...
}
$tpl->setCacheLifetime(300);
$tpl->display(); |
|
Thanks a lot, it works.
But why 'cache_lifetime' is locked after 'isCached()' calle, it's new feature or just a bug? |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Thu Jan 12, 2012 6:28 pm Post subject: |
|
|
it's neither. It's behavior.
fetch(), display(), isCached(), … all access a real deal template object. Those are their own objects in Smarty3.1. This allows you to create multiple templates from the same smarty instance, but all differing in configuration, data and whatnot.
that createTemplate() trick is pretty much what smarty does internally. With the exception that you now know the referenced template and can access its properties.
I admit the docs could do a much better job at communicating this. there is a doc for createTemplate() but nothing says why you'd actually want to use this. _________________ Twitter |
|
Back to top |
|
FalconIA Smarty n00b
Joined: 11 Jan 2012 Posts: 3
|
Posted: Fri Jan 13, 2012 10:10 am Post subject: |
|
|
Thanks a lot for your explanation.
Learn a lot.
For clearCache():
Use
Code: | $template_object = $smarty->createTemplate($template, $cache_id);
$template_object->clearCache(); |
or
Code: | $smarty->clearCache($template, $cache_id); |
The first one seems not work.
I try to find the doc of template object (created by createTemplate()).
Is there a list of functions/members of template object? |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|