RE: [SMARTY] Cache result from db-query?
| From: | Eskil Keskikangas | Date: | Tue, 04 Mar 2003 16:24:11 +0000 |
| Subject: | RE: [SMARTY] Cache result from db-query? | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8394@lists.php.net to get a copy of this message | ||
I did like this. I don't know if it's a good way to solve the problem, but it works prefect for me.
The script:
$smarty->caching = 2;
if (!$smarty->is_cached("topTen.tpl",$cat)) {
$data = $qe->getAllThingsFromCategory();
$smarty->assign("topData",serialize($data->itemsArray));
}
$smarty->cache_lifetime = 600;
$topTen = $smarty->fetch("topTen.tpl",$cat);
$result = unserialize($topTen);
$smarty->assign("result", $result);
$smarty->caching = 0;
$smarty->display('index.tpl');
Template (topTen.tpl):
{$topData}
Template (index.tpl):
{foreach item=item from=$result}
{$item.productName}{$item.productPrice}
{/foreach}
This way I can cache the result from the query in a serialize array in the templatefile.
Please give me some feedback to this. Is there a better way to do this?
BG
Eskil
At 15:09 2003-03-04 +0100, Eskil Keskikangas wrote:
Will this work? function smarty_function_top_ten_products($params, &$smarty) {extract($params);$smarty->caching = 2;if (!$smarty->is_cached("TORGET/topTen.tpl")) { $data = rand(0,10); $smarty->assign("topData",$data); }$smarty->cache_lifetime = 180;return $smarty->fetch("TORGET/topTen.tpl");} What will become cached when i define "caching = 2" in the function? /Eskil At 14:51 2003-03-04 +0100, Peter Billen wrote:forgot url: http://smarty.php.net/manual/en/language.function.insert.php Peter -----Original Message----- From: Peter Billen [mailto:peter@clueless.be] Sent: dinsdag 4 maart 2003 14:39 To: smarty-general@lists.php.net Subject: RE: [SMARTY] Cache result from db-query? I am not used to caching & smarty, but I think it's impossible to cache database queries with smarty. The only thing that smarty (should?) cache is output of 'data'. So I think it's only possible to cache a parsed template (or parts of it), so next time, smarty does not have to re-loop the whole datastructures again. However, I could be wrong! You may want to look to the 'insert' function, in order to cache parts of a template (and not the whole template itself). Peter -----Original Message----- From: Eskil Keskikangas [mailto:eskil@funplanet.com] Sent: dinsdag 4 maart 2003 14:32 To: smarty-general@lists.php.net Subject: [SMARTY] Cache result from db-query? Hi, I want to cache a small part of my output. It's a toplist from a mysql-db that results in a slow query. But I don't understand how to do this. If I enable cache won't all output get cached then? Give me a hint please. :) BG Eskil -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php-- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php