Re: [SMARTY] Suggestion

From: Date: Sun, 14 Apr 2002 03:52:53 +0000
Subject: Re: [SMARTY] Suggestion
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-3690@lists.php.net to get a copy of this message
I tend to use a system that looks like this to achieve different cache rates: $t = new Smarty; $t->caching=true; $content = box('foo') . box('bar') .box('blah'); //caching no longer needed for outer template $t->caching=false; $t->assign('content',$content); $t->display('page.tpl'); function box($box_type) { global $t; switch ($box_type) { case 'foo': $t->cache_lifetime=3600; //one hour //test cached/gen content/assign $ret = $t->fetch('box.tpl'); break; case 'bar': $t->cache_lifetime=300; //5 minutes //test cached/gen content/assign $ret = $t->fetch('box.tpl'); break; //and so on } return $ret; } Good luck! Jason ----- Original Message ----- From: "Norbert Röcher" <norbert.roecher@t-online.de> To: <smarty-general@lists.php.net> Sent: Friday, April 12, 2002 4:46 AM Subject: [SMARTY] Suggestion > Hi all, > > currently a cached file contains the timestamp of when it of was > generated. > > Problem: I use "if ($this->is_cached)" to intercept useless > db-operations (what a surprise :-D) for blocks included within a > template. Now i want to support different expiration times for the > included blocks, and want to set $cache_lifetime to the minimum value > of these expiration times. So the whole site will expire, when one > block expires. Normally not a problem, but to get the expiration times, > i've got to read them from the db, because $cache_lifetime has to be > set to its value BEFORE checking the cached file. And in this situation > "$this->is_cached" is absolutely useless, because it doesn't prevent > from unwanted db-operations. > > I think it would make more sense, when cached files contain the > timestamp of expiration. Should look like kind of this: > > write cache_info: > cachedFile_timestamp = time() + cache_lifetime; > > read cache_info: > if (cachedFile_timestamp > time()){ > is_cached = true; > } > > The benefit would be to be able to set $cache_lifetime also AFTER the > check for cache_expiration. Allows much more dynamic... > > What do you think? > > Regards, > Norbert > > > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

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