View previous topic :: View next topic |
Author |
Message |
AnyOne Smarty n00b
Joined: 10 Jan 2019 Posts: 4
|
Posted: Thu Jan 10, 2019 11:06 pm Post subject: Cached file does not correctly list all file dependencies |
|
|
I have two templates A and B that both include the same set of other "sub"-templates with no fancy content, just plain html.
I use the following config
Code: | $smarty->caching = true;
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
$smarty->setCacheLifetime(3600);
$smarty->setCompileCheck(true); |
Now when starting from an empty template_c, an empty cache directory, and after executing
Code: | if (!$smarty->isCached('A.tpl') {
$output = $smarty->fetch('A.tpl');
if (!$smarty->isCached('B.tpl') {
$output = $smarty->fetch('B.tpl'); |
I detect that the cache for template A contains a correct list of file dependencies (the included "sub"-templates), while B does not, it just lists the dependency to its own template.
So if I change the content of one of the sub-templates, only A gets updated.
That does not make sense to me
Any ideas?
Thanks in advance for any help,
AnyOne
PS: using Smarty v3.1.33 |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jan 11, 2019 9:19 am Post subject: |
|
|
You're confusing compilation and caching.
Each template is compiled separately.
templates_c is compiled templates. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jan 11, 2019 9:21 am Post subject: |
|
|
Adding to that, I would strongly adwise against long caching times in development and CACHING_LIFETIME_CURRENT in general.
20 seconds with CACHING_LIFETIME_SAVED is more than enough to test caching in development. |
|
Back to top |
|
AnyOne Smarty n00b
Joined: 10 Jan 2019 Posts: 4
|
Posted: Fri Jan 11, 2019 9:31 am Post subject: |
|
|
Even if I had mixed up compilation and caching:
changing a sub-template should trigger recompilation of this sub-template and therefore also the re-compilation of A and B. And finally the cached versions of A and B should be updated, too.
If I'm wrong, please explain. Thanks. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jan 11, 2019 7:38 pm Post subject: |
|
|
You are wrong.
Changing a template file triggers recompilation of a template file. Full stop.
Compiled template is merely a .smarty file converted to actual PHP code, nothing more. It's not cache, which contains actual data. |
|
Back to top |
|
AnyOne Smarty n00b
Joined: 10 Jan 2019 Posts: 4
|
Posted: Fri Jan 11, 2019 9:50 pm Post subject: |
|
|
OK, the other way round: no conceptual talk, just plain practice.
- I have two templates A and B that both include template C.
- All three templates were compiled, rendered output of A and B were cached (since A and B were fetched once).
- Then I modify C.
- My question: how can I configure Smarty to fetch the produced content of A and B, both having the modified content of C in it?
Using the config described in my initial post, only the fetched content returned by A will contain the modified content C.
But when fetching B it still contains the old content of C !
Isn't this surprising? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Jan 14, 2019 4:35 pm Post subject: |
|
|
It's already configured that way.
If you change the template, please manually clear cache.
This is in the documentation.
And on production, compileCheck should be false. |
|
Back to top |
|
AnyOne Smarty n00b
Joined: 10 Jan 2019 Posts: 4
|
Posted: Thu Jan 17, 2019 10:33 am Post subject: |
|
|
And the funny thing is I found a solution that I can't explain:
Code: | $smarty = new Smarty;
... // doing my config
if (!$smarty->isCached('A.tpl') {
$output = $smarty->fetch('A.tpl');
$smarty = new Smarty;
... // doing my config
$smarty = new Smarty;
if (!$smarty->isCached('B.tpl') {
$output = $smarty->fetch('B.tpl');
|
Restarting with a fresh Smarty instance does the trick !???
Hopefully this helps other people facing a similar issue.
And hopefully someone is capable to explain this |
|
Back to top |
|
|