Re: More on cache with database templates

From: Date: Mon, 28 Jan 2002 23:20:10 +0000
Subject: Re: More on cache with database templates
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2586@lists.php.net to get a copy of this message
You are correct, the example is a bit misleading. The timestamp returned should be the value from the datasource, but in the example I'm using mktime() as a faked timestamp. I'll adjust the example. Dominique Peretti wrote: > > 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. > > --- > You are currently subscribed to smarty as: monte@ispi.net > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at > http://www.phpinsider.com/php/code/Smarty/ -- Monte Ohrt <monte@ispi.net> http://www.ispi.net/

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