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

Registered plugin as function with nocache

 
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 -> General
View previous topic :: View next topic  
Author Message
aknight720
Smarty n00b


Joined: 17 Mar 2017
Posts: 4

PostPosted: Fri Mar 17, 2017 8:16 am    Post subject: Registered plugin as function with nocache Reply with quote

I have taken over someones else work and having a problem with a registered plugin function still being cached when cacheable is set to false

its setup as follows:-

Code:
$template->registerPlugin('function','showRuleViolations', 'getRuleViolations', false);


the function gets some values from a mysql database and returns them in an html style format

I have also added in the template the nocache tags when the function is being used:-

Code:
{!nocache!}
{!showRuleViolations!}
{!/nocache!}


The version of Smarty being used is 3.1.30 on PHP 5.6

Could someone please suggest why it's still being cached?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Mar 17, 2017 12:16 pm    Post subject: Reply with quote

Can you provide a testcase demonstrating your issue?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Mar 20, 2017 7:22 pm    Post subject: Reply with quote

I think I have an answer to this.
If you don't want the output of your function cached, add a "nocache" flag.

F.e.
Code:
{myfunction nocache}
Back to top
View user's profile Send private message
aknight720
Smarty n00b


Joined: 17 Mar 2017
Posts: 4

PostPosted: Mon Mar 20, 2017 9:23 pm    Post subject: Reply with quote

AnrDaemon wrote:
I think I have an answer to this.
If you don't want the output of your function cached, add a "nocache" flag.

F.e.
Code:
{myfunction nocache}


Is that not just the same as I wrote in my OP with enclosing it in nocache tags?

Also according to the docs say the 4th param of registerPlugin is bool cacheable which I have set to false.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Mar 21, 2017 12:38 am    Post subject: Reply with quote

"According to docs" the use of these parameters is discouraged.
Back to top
View user's profile Send private message
aknight720
Smarty n00b


Joined: 17 Mar 2017
Posts: 4

PostPosted: Tue Mar 21, 2017 11:07 am    Post subject: Reply with quote

AnrDaemon wrote:
"According to docs" the use of these parameters is discouraged.


Which is why I tried enclosing it in nocache tags like in the example, I have tried your suggestion and the function data is still being cached.

Code:
{!nocache!}
{!showRuleViolations!}
{!/nocache!}


and


Code:
{!showRuleViolations nocache!}
Back to top
View user's profile Send private message
aknight720
Smarty n00b


Joined: 17 Mar 2017
Posts: 4

PostPosted: Tue Mar 21, 2017 12:26 pm    Post subject: Reply with quote

I have managed to identify the issue, it's also caching the users id, so what is being shown is correct, but not what was expected because it's the wrong users info, at least now I can see the issue, just need to try to find a way to fix it Smile
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Mar 21, 2017 3:15 pm    Post subject: Reply with quote

If your function is implicitly using template variables, then yes, the results may look cached even if they aren't necessarily are.

To avoid such issues, alyways explicitly pass any control variables to the function as parameters.
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 -> 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