Re: [SMARTY] Cache and insert
| From: | Nino Katic | Date: | Mon, 27 Jan 2003 19:22:19 +0000 |
| Subject: | Re: [SMARTY] Cache and insert | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7349@lists.php.net to get a copy of this message | ||
Hi Ferdinad,
Thank you for help, but I think that i didn't explain the problem very well.
The point is that the data is in the DB and actually gets change very often.
To be more specific it's kind of a yahoo thing. There are categories,
subcategories etc. and "in them" there are data such as link to someone
page, date of creation, date of update etc. which gets change when user
enters it into DB. So, my function prepareData makes sql query, grabs that
data and assigns it to smarty template. Now, I want to make all this using
cache. $ID is a variable that I use only to tell the function from which
categorie i want to show the data. So, I make sql query like this: select *
from datatable where categories=$ID. Problem is that one time there will be
for example 5 rows returned, and other time (when some user enters his data
in that categorie) there will be 6. So, how to make use of cache here? Thx.
Nino
Ferdinand Beyer wrote:
> Hi Nino,
>
> I'm not sure if I understood you right. If you just want to use
> caching, you do not have to change anything at all. Simply set
> $smarty-
>> caching = true and your templates will be cached.
>
> Caching means that the output of your template _after_
> prepareData() has run and _after_ the arrays are layouted nicely by
> your template is saved and loaded next time instead of running the
> template again.
>
> So if the template is cached, there is no need to call prepareData()
> since the data will not be processed. That's why you should test this
> before calling prepareData():
>
> if (!$smarty->is_cached('your_template.tpl'`)) {
> prepareData();
> }
> $smarty->display('your_template.tpl');
>
> I guess you want to use the same template for different data
> specified by the $id in prepareData($id), don't you? If yes, I
> recommend you to use cache ids and to include $id in the cache id
> to make sure that different ids will be cached separately.
>
> Inserts are smarty plugin functions that are _never_ cached. So you
> only need them in special situations, eg. if you want to add the
> current time on your page. In your situation, you don't need an insert
> tag since you want to cache the result of prepareData(). If not,
> please don't enable caching for this template!
>
> You were talking about plugin classes - Smarty doesn't use classes
> but functions for plugins. Maybe you would like to read the
> documentation pages at http://smarty.php.net for plugins,
> caching
> (including cache ids) and insert tags.
>
> Hope that helps!
>
> --
> Ferdinand Beyer
> <fbeyer@clickhand.de>