Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

isCached function gives wrong result

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
tiger42
Smarty n00b


Joined: 14 Dec 2015
Posts: 4

PostPosted: Mon Dec 14, 2015 4:51 pm    Post subject: isCached function gives wrong result Reply with quote

Hello,

after updating Smarty to version 3.1.28 I have noticed that some of the unit tests of my application were failing. After some investigation I found out that the Smarty function "isCached" gives the wrong return value (or at least a different result than in the previous Smarty version...).
Here is a simplified section of code that demonstrates the issue:
Code:

require_once 'smarty/libs/Smarty.class.php';

$smarty = new \Smarty();
$smarty->setTemplateDir('.');
$smarty->setCompileDir('test/');
$smarty->setCacheDir('test/');
$smarty->setCaching(\Smarty::CACHING_LIFETIME_CURRENT);

$tpl = $smarty->fetch('test.tpl');
var_dump($smarty->isCached('test.tpl'));  // true
$smarty->clearAllCache();
var_dump($smarty->isCached('test.tpl'));  // true -> should be false!
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Dec 14, 2015 5:02 pm    Post subject: Reply with quote

The Smarty::isCached() result is likely cached.
That said, your test do not show wrong results per se.
Rendering a template, clearing cache, and rendering template again is and unexpected turn of events.
Also, take a look at CACHING_LIFETIME_SAVED. It gives a better caching control.
Back to top
View user's profile Send private message
tiger42
Smarty n00b


Joined: 14 Dec 2015
Posts: 4

PostPosted: Mon Dec 14, 2015 7:35 pm    Post subject: Reply with quote

Maybe my code example is not really relevant in real world applications (although I am sure one could find a more relevant example...), but that is not the point. The point is: The isCached() function returns an unexpected result in some cases, which is not documented anywhere and breaks compatibility with older versions of Smarty. So I still think that this is a bug that should be fixed.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Dec 15, 2015 2:35 am    Post subject: Reply with quote

This is fixed now on github in the master branch
Back to top
View user's profile Send private message
tiger42
Smarty n00b


Joined: 14 Dec 2015
Posts: 4

PostPosted: Tue Dec 15, 2015 7:50 am    Post subject: Reply with quote

Thank you very much! Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs 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