Re: [SMARTY] Cache time
| From: | messju mohr | Date: | Fri, 07 Mar 2003 18:03:16 +0000 |
| Subject: | Re: [SMARTY] Cache time | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8480@lists.php.net to get a copy of this message | ||
On Thu, Mar 06, 2003 at 12:02:04PM +0100, Ferdinand Beyer wrote:
> Hi,
>
> In one of my current projects I need to test whether a template's
> cache is newer than the data from a database.
>
> In detail, the site has a news ticker system that isn't updated very
> often. The news are saved in a database. For the front page I want
> to fetch the titles of all topical news and pass them to the template.
>
> Since I want to cache the result, it would be nice to pass a
> timestamp to the is_cached() method in order to test whether the
> cache is newer than my news in the database. So I only have to
> fetch the timestamp of the latest news instead of running the
> template all the time:
>
> // $time contains a unix timestamp of the latest news
> if (!$smarty->is_cached($tpl, $cache_id, $time)) {
> $smarty->clear_cache($tpl, $cache_id);
> // fetch and assign news from database
> }
> $smarty->display($tpl, $cache_id);
maybe you can set $smarty->cache_lifetime to a lower value dynamically,
before you call is_cached():
$smarty->cache_lifetime = time() - $timestamp_of_newsticker;
i did'nt test it, but would be interested if such construct works :)
have fun
messju