[prev in list] [next in list] [prev in thread] [next in thread]
List: smarty-general
Subject: [smarty] Re: More on cache with database templates
From: Monte Ohrt <monte () ispi ! net>
Date: 2002-01-28 23:20:10
[Download RAW message or body]
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 leave-smarty-700385W@lists.ispi.net
> Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/
---
You are currently subscribed to smarty as: smarty@progressive-comp.com
To unsubscribe send a blank email to leave-smarty-700385W@lists.ispi.net
Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic