Re: [SMARTY] cache date and time

From: Date: Wed, 05 Jun 2002 11:53:56 +0000
Subject: Re: [SMARTY] cache date and time
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4611@lists.php.net to get a copy of this message
I think I had a similar situation to what you had in the past, i.e. I knew how long I wanted to have the template cached (ever since the last update in your case) but I did not know if or how long the current template was cached. I used this function to populate the $smarty->cache_lifetime: /** * return the $Smarty->cache_lifetime to cache a page since a certain point in the past * * @author Jason E. Sweat * @since 2001-08-01 * @param timestamp $cache_time the time from which the data should be cached * @param int $future_cache optional - the seconds to use if a future value is passed in $cache_time * @return int the number of seconds to pass to $Smarty->cache_lifetime to cache_since */ function cache_since($cache_time, $future_cache = 3600) { if ($cache_time > time()) { return $future_cache; } else { return (time() - $cache_time); } } you would then just code your application using the normal: if (!$smarty->is_cached) { //db queries //assigns } $smarty->display(template, cache_id); And you know that if your cache is sufficiently up to date, the cached version will display, otherwise you will generate a new version of the page and cache it. Hope that helps. Jason ----- Original Message ----- From: "Mattia Wow" <nocciolo@yahoo.com> To: "smarty" <smarty-general@lists.php.net> Sent: Wednesday, June 05, 2002 3:46 AM Subject: Re: [SMARTY] cache date and time > > > I simply would like to use the Smarty cache wrapper, > > but not to use the caching lifetime method, but use > > the cached page as long as the datas are STILL > > VALID, > > that means until I don't have fresher datas in my > > datasouce (can be a DBMS). > > > > For example: > > I'm handling a mailing-list and want to use my cache > > page while the mailing list isn't changed (ie: > > received new message). In this case a cached page > > can > > last several days or can expire after a few minutes > > (who knows). But It's clear that the lifetime method > > doesn't fit here!). > > Please let me know about your decision, because if you > decide to not incorporate such a funcyion in Smarty > I'll have to write my ow cache handler functions. > > Bye > > ______________________________________________________________________ > Non perderti un solo gol! Iscriviti al FIFA VIP Club > http://it.yahoo.com/mail_it/foot/?http://it.sports.yahoo.com/vipclub/index.h tml > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

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