Page 1 of 1

Question about caching [SOLVED]

Posted: Fri May 04, 2007 2:39 pm
by LeisureLarry
I´m working on a very bad implemented members area for one of my customers. The former coders have done it the following way:

1. They made content page let´s say with the id 40 (not cached).
2. They made a special template for this page.
3. This template has no $content in it, but a $customerContent for a user defined tag.
4. In the user defined tag they made an if statement for the login and decided to show:
a) the page with id 40 (direkt grabbing from the db and using a print statement)
b) custom content depending on the login

Now I´m working on implementing the usage of smarty in this solution.
The problem is that I need to render code from a string using smarty-tags.
The following way this would work (code of the user defined tag):

function bb_replace($tpl_source, &$smarty)
{
$page = '';
if (...) {
$page .= 'a';
}
} else {
$page .= 'b';
}     
}
return preg_replace("//", $page, $tpl_source);
}

global $smarty;
//$smarty->caching = 0;
//$smarty->clear_all_cache();

$smarty->register_prefilter("bb_replace");
$smarty->fetch("file:(...)customer.tpl", null, null, true);

I only need a special template which simply contains:

and nothing else.

I only have one problem with this new solution:
CMS MS caches this page (even if the content page has selected no caching)!

Therefore if I reload this page and the if statement would be the other case as before,
it shows the same as before. Deleting the cache in the admin interface, solves the
problem for the next site loading, but after that it´s cached by CMS MS.

I tried the two commented lines in the user defined tag, but that didn´t solved my
problem. Does anybody know how and where I can deactivate the caching for this page?

Greats from Germany
LeisureLarry

Re: Question about caching

Posted: Fri May 04, 2007 2:43 pm
by LeisureLarry
One thing to notice:

$page contains in case b user defined tags or module tags, therefore this is why I need smarty.

Re: Question about caching

Posted: Fri May 04, 2007 3:04 pm
by Pierre M.
Hello LeisureLarry,

This topic is far too much deep inside CMSms internals for me. I have just a simple (silly) question :
What about unchecking the "cachable" flag in the options tab in the admin of the page ?
Sorry if this is irrelevant due to the internal tweakings.

Pierre M.

Re: Question about caching

Posted: Fri May 04, 2007 3:29 pm
by LeisureLarry
@Pierre M.  (thanks for your reply):

That´s why I wrote:
1. They made content page let´s say with the id 40 (not cached).

The content page itself has selected in its options tab to not be cached.

I simply don´t know why its cached, even if caching is disabled.

Besides the installation is CMS MS 1.06, just to mention.

Re: Question about caching

Posted: Mon May 07, 2007 8:39 am
by LeisureLarry
Does noboy have a clue, where cms ms / smarty is caching this content and how I can disable this behaviour.

Re: Question about caching

Posted: Mon May 07, 2007 9:41 am
by cyberman
Have you tried to switch off caching in /lib/content.functions.php in line 56?

Code: Select all

		$this->caching = false;

Re: Question about caching

Posted: Thu May 10, 2007 10:08 am
by LeisureLarry
Thanks cyberman, it wasn´t the correct line, but this file helped me a lot.

My user defined tag is now:

function bb_replace($tpl_source, &$smarty)
{
$page = '';
if (...) {
$page .= 'a';
}
} else {
$page .= 'b';
}   
}
return preg_replace("//", $page, $tpl_source);
}

global $smarty;
$smarty->caching = false;
$smarty->force_compile = true; // THIS SOLVED THE PROBLEM

$smarty->register_prefilter("bb_replace");
$smarty->fetch("file:(...)customer.tpl", null, null, true);

Re: Question about caching

Posted: Thu May 10, 2007 10:14 am
by tsw
force compile will slow page rendering considerably, but it might be the only option for you

Re: Question about caching

Posted: Thu May 10, 2007 2:16 pm
by LeisureLarry
As this solution is only implemented in one single page, I don´t think it will be a great problem.

But thanks for the info.

Greats from Germany
LeisureLarry