Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Cached file does not correctly list all file dependencies

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
AnyOne
Smarty n00b


Joined: 10 Jan 2019
Posts: 4

PostPosted: Thu Jan 10, 2019 11:06 pm    Post subject: Cached file does not correctly list all file dependencies Reply with quote

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 Confused
Any ideas?

Thanks in advance for any help,
AnyOne

PS: using Smarty v3.1.33
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1572

PostPosted: Fri Jan 11, 2019 9:19 am    Post subject: Reply with quote

You're confusing compilation and caching.
Each template is compiled separately.
templates_c is compiled templates.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1572

PostPosted: Fri Jan 11, 2019 9:21 am    Post subject: Reply with quote

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
View user's profile Send private message
AnyOne
Smarty n00b


Joined: 10 Jan 2019
Posts: 4

PostPosted: Fri Jan 11, 2019 9:31 am    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1572

PostPosted: Fri Jan 11, 2019 7:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnyOne
Smarty n00b


Joined: 10 Jan 2019
Posts: 4

PostPosted: Fri Jan 11, 2019 9:50 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1572

PostPosted: Mon Jan 14, 2019 4:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnyOne
Smarty n00b


Joined: 10 Jan 2019
Posts: 4

PostPosted: Thu Jan 17, 2019 10:33 am    Post subject: Reply with quote

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 Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP