More on cache with database templates
| From: | Dominique Peretti | Date: | Mon, 28 Jan 2002 22:52:00 +0000 |
| Subject: | More on cache with database templates | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-2585@lists.php.net to get a copy of this message | ||
Finally understood that I overlooked the example from the doc :
// put this function somewhere in your application
function get_db_template ($tpl_name, &$tpl_source, &$tpl_timestamp,
$get_source=true, &$smarty_obj) {
if($get_source) {
// do database calls (or whatever) here to fetch your template,
populating
// $tpl_source and $tpl_timestamp.
$tpl_source = "This is a simulation of a template fetched from a
db.";
$tpl_timestamp = mktime();
} else {
// just populate $tpl_timestamp.
$tpl_timestamp = mktime();
}
return true;
}
With this kind of example, the cache will always be regenerated because
the part :
} else {
// just populate $tpl_timestamp.
$tpl_timestamp = mktime();
}
.. will always return a more recent value than the one stored in the cache
file, which is wrong I think.
I know it's just an example, but the doc should be clearer about what is
happening here. I would prefer something like that :
// put this function somewhere in your application
function get_db_template ($tpl_name, &$tpl_source, &$tpl_timestamp,
$get_source=true, &$smarty_obj) {
if($get_source) {
// do database calls (or whatever) here to fetch your template,
populating
// $tpl_source and $tpl_timestamp.
$tpl_source = "This is a simulation of a template fetched from a
db.";
$tpl_timestamp = mktime();
} else {
// just populate $tpl_timestamp.
$tpl_timestamp = /* return the timestamp when the template was last
changed or 0 if you don't mind the cache being regenerated before normal
expiration when the template has changed */
}
return true;
}
Please Monte or Andrei tell me if I'm right.