Re: [SMARTY] Cache question

From: Date: Thu, 20 Feb 2003 20:17:46 +0000
Subject: Re: [SMARTY] Cache question
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8050@lists.php.net to get a copy of this message
Nino Katic wrote:
I'm not sure how to handle DB data that actually gets change quite often (relative) within Smarty. As I see it, I can use smartys function {insert} that will insert code that will not be cached or I could delete cache files when the user inserts new data in DB. So what do you suggest to use? Nino
You can cache an insert using different cache times! Just set $smarty->caching = 2 and then in your insert function, specify a cache time, fetch() the template and return it to the calling template. For instance, here is an example of an insert function that users caching: function insert_box_poll($params, &$smarty) { if (!$smarty->is_cached("poll.tpl","poll","poll")) { $result = db_query("SELECT * FROM dos_poll_dat WHERE status = 'on'"); while ($row = db_results($result)) { $e_poll["id"] = $row["p_id"]; $e_poll["question"]= $row["p_question"]; $e_poll["votes"]= $row["p_votes"]; $e_poll["comments"]= $row["p_comments"]; $e_poll["options"][$row["pa_id"]]["id"] = $row["pa_id"]; $e_poll["options"][$row["pa_id"]]["option"] = $row["pa_option"]; } $smarty->assign("e_poll",$e_poll); } // set the cache timeout and display the page $smarty->cache_lifetime = 180; return $smarty->fetch("poll.tpl","poll","poll"); } Make sense? If it doesn't, feel free to email me off the list and I'll clarify a little more. ~Paul

« previous php.smarty.general (#8050) next »