1
brash
How do you force smarty cache bypass?
  • 2004/11/16 1:00

  • brash

  • Friend of XOOPS

  • Posts: 2206

  • Since: 2003/4/10


Hi All,

I have a small piece of code that I am looking to have executed at the end of every single page, regardless of any cache settings that might be set at block or module level. To do this I have tried using the smarty insert tag in footer.php, but as yet am not having any luck. I'm not sure if it is placement of my code, or if footer.php is not the best place for it, but it seems that my code using the insert tag are still being cached.

I entered the following code on line 31 of footer.php;
function insert_test()
    {
    
$Test='test';
    return 
$Test;
    }

I then added the following in my theme.html file;
<{insert name='test'}>


As you'd expect this returns the word test where the insert tag is placed, however, with module caching enabled it is still not displayed when coming from cache, which to me means the code is not being executed. It was my impression that bybassing of cache, and forcing the code execution was what the insert tag was specifically intended for, so I can only assume I've stuffed it up here somewhere.

It is obvious that what I'm wanting to do can be done as the $xoops_footer tag for example is not cached regardless of any caching settings, so I was just looking for a bit of a hand here.


*Edit*

Ok, it would seem that $xoops_footer is cached, it's just that anytime it is changed the cache is cleared. This is slightly different to what i'm after as I want everything else to be cached APART from the insert tag.

2
brash
Re: How do you force smarty cache bypass?
  • 2004/11/16 2:26

  • brash

  • Friend of XOOPS

  • Posts: 2206

  • Since: 2003/4/10


From a few posts I've read I'm starting to get the impression that I cannot do what I'm trying to do . It seems that there is no way at present for individual elements of a page to be dynamically updated without updating the entire page. There is a hack to update the cache only on content change, but as I am wanting to execute code on every single page, this would mean that the page would be being updated every refresh, so I'd be better off just not using cache in the first place.

Does anyone know if this will be changed in XOOPS 2.2 at all?

3
Dave_L
Re: How do you force smarty cache bypass?
  • 2004/11/16 6:28

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I found the test I had done previously. It's similar to yours.

In .php file:

// --------------------------------------------------------------
// For testing caching. #*#DEBUG#
// Must start with "insert_" to be accessed by Smarty insert tag.
function insert_chess_show_date()
{
    return 
date('Y-m-d H:i:s');
}


In template:

<{* For testing caching#*#DEBUG# *}>
<table width="%25">
<
tr><td>Page generated:td><td><{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}>td>tr>
<
tr><td>Current time:td><td><{insert name="chess_show_date"}>td>tr>
table>


I could verify that it was working by comparing the timestamps. I don't know if this helps you.

4
brash
Re: How do you force smarty cache bypass?
  • 2004/11/16 7:29

  • brash

  • Friend of XOOPS

  • Posts: 2206

  • Since: 2003/4/10


Hi Dave,

Thanks so much for the reply, however it still isn't working for me . I placed your php code in footer.php, and the html in my theme.html file with exactly the same result. It works fine the first time, but nothing at all is displayed once content is coming out of module cache apart from the $smarty.now section. I also tried just adding the html to a custom template, and again it works for the first time while still out of cache, but upon a refresh I actually got a blank page.

Any ideas why this might be ....

5
Dave_L
Re: How do you force smarty cache bypass?
  • 2004/11/16 8:24

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Quote:
blank page


Have you tried turning on the various debug options? That could be a syntax error, or possibly the "insert" function isn't at a place where it's available when the template needs to be generated.

6
brash
Re: How do you force smarty cache bypass?
  • 2004/11/16 8:34

  • brash

  • Friend of XOOPS

  • Posts: 2206

  • Since: 2003/4/10


Yep, just did it now. PHP debug brings back this error;
Quote:
Error [Xoops]: Smarty error: [in ithq/theme.html line 160]: [plugin] could not load plugin file 'insert.chess_show_date.php' (Smarty.class.php, line 2543) in file F:\web\amsdemo\class\smarty\Smarty.class.php line 2652

7
Dave_L
Re: How do you force smarty cache bypass?
  • 2004/11/16 8:59

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


It's been a while since I used that code, and I don't remember if I had to do anything else to get it to work.

Are you sure that function is available when that page is processed? It may need to be in a common file that's always included, or located in the Smarty plugins directory as described here: http://smarty.php.net/manual/en/plugins.inserts.php

Alternatively, the insert-tag has a parameter for specifying the name of the .php file that contains the function: http://smarty.php.net/manual/en/language.function.insert.php

8
brash
Re: How do you force smarty cache bypass?
  • 2004/11/16 9:07

  • brash

  • Friend of XOOPS

  • Posts: 2206

  • Since: 2003/4/10


Thanks for your help Dave .

I've placed the function in footer.php which should be called on every page as far as I know? Perhaps that is my mistake . I'll have another read of the insert doco, thanks .

9
brash
Re: How do you force smarty cache bypass?
  • 2004/11/17 0:33

  • brash

  • Friend of XOOPS

  • Posts: 2206

  • Since: 2003/4/10


You little rippa !!

The plugin insert was the key Dave . I just needed to shift my insert function off to it's own correctly named file (insert.function_name.php) in the smarty plugin directory with an include_once statement in footer.php and away she goes .

I'll just have to get my homework checked to ensure I have done it in the most efficient way, and then I have a very cool little hack to release .

10
brash
Re: How do you force smarty cache bypass?
  • 2004/11/17 0:51

  • brash

  • Friend of XOOPS

  • Posts: 2206

  • Since: 2003/4/10


Correction, if I place my insert function in a file in the plugin directory, then there is no need to have the include_once statement in the footer.php file at all .

Login

Who's Online

357 user(s) are online (247 user(s) are browsing Support Forums)


Members: 0


Guests: 357


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits