darren chamberlain wrote:
> > I have several "tags" in a template that each query
> > the  database, often the same table. Which is the
> > better way to approach getting my data?
> >
> > 1) Using several "INCLUDE" directives in my template,
> > each which query the database
> >
> > or
> >
> > 2) Query the database in my handler, making the data
> > available to all my INCLUDE directives.
> >
> > It seems wasteful to query the same table in several
> > INCLUDE directives when I could have just query that
> > table once.
> 
> My advice would be to write some plugins that do the work, and
> call the plugins from your templates.

Personally, I would do it in the handler.  I think it makes a cleaner
separation to do all of your work before you start running the
template.  Opinions vary, and TT supports many approaches.


> For expensive calculations
> (like database queries), have the plugins either be Singletons or
> implement their own caches (I like Perrin Harkin's
> Template::Plugin::Cache module that was posted a few weeks ago
> see 
><URL:http://www.template-toolkit.org/pipermail/templates/2001-August/001320.html>),
> although I don't know if this had made it to CPAN yet.

Thanks!  It hasn't made it to CPAN yet.  I wanted to do one more round
of improvements to it first.  Of course, you can always use the
Cache::Cache modules directly from your code, which is all that my
module does.

- Perrin


Reply via email to