View previous topic :: View next topic |
Author |
Message |
aknight720 Smarty n00b
Joined: 17 Mar 2017 Posts: 4
|
Posted: Fri Mar 17, 2017 8:16 am Post subject: Registered plugin as function with nocache |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Mar 17, 2017 12:16 pm Post subject: |
|
|
Can you provide a testcase demonstrating your issue? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Mar 20, 2017 7:22 pm Post subject: |
|
|
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 |
|
aknight720 Smarty n00b
Joined: 17 Mar 2017 Posts: 4
|
Posted: Mon Mar 20, 2017 9:23 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Mar 21, 2017 12:38 am Post subject: |
|
|
"According to docs" the use of these parameters is discouraged. |
|
Back to top |
|
aknight720 Smarty n00b
Joined: 17 Mar 2017 Posts: 4
|
Posted: Tue Mar 21, 2017 11:07 am Post subject: |
|
|
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 |
|
aknight720 Smarty n00b
Joined: 17 Mar 2017 Posts: 4
|
Posted: Tue Mar 21, 2017 12:26 pm Post subject: |
|
|
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 |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Mar 21, 2017 3:15 pm Post subject: |
|
|
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 |
|
|