You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by David Duddleston <da...@i2a.com> on 2001/05/23 23:15:23 UTC

checking Template validity

Mentioned in a previously. I would like to cache the output of frequently
accessed Templates. I can validate my data against a cache, but validating
the Template is questionable. It seems a Template.isModified(time) would be
useful for, at least for me. I know
org.apache.velocity.runtime.resource.Resource has a isSourceModified, but
unless I missed something, it does not validate referenced Templates or
files from import or parse directives. Any thoughts. Would it be difficult
to implement?

-david


RE: checking Template validity

Posted by David Duddleston <da...@i2a.com>.
> However, how often in a production system will you change templates?

Not very often and thus this is not a big concern. The compulsive side of me
wants to validate the template along with the data, but I'm guessing there
is no efficient way to do this when Templates contain #import and #parse and
possibly #marco. I have this mindset due to working with a component where
if you validate a component, it will check any components in its hierarchy
for validity also. I want to treat #parse like a component, but it does not
really work that way, since components usualy need some sort of params to
determine its actions. When I get real comfortable with Velocity, I'll
probably think of some way to emulate a component template system. Right
now, I'm just dropping in a bunch of components into a context for the
template user to access, so they can determine what data goes unto the page,
sort of like a pull model, but this seem a bit fragile and it makes caching
a little difficult.

> public Template getTemplate( Reader )

That would definately make it easy to pull templates from a datasource.

> It was a long day today, so I am basically babbling

All the babbling is very much appreciated.

Thanks once again

-david






Re: checking Template validity

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
David Duddleston wrote:
> 
> Mentioned in a previously. I would like to cache the output of frequently
> accessed Templates. I can validate my data against a cache, but validating
> the Template is questionable. It seems a Template.isModified(time) would be
> useful for, at least for me. I know
> org.apache.velocity.runtime.resource.Resource has a isSourceModified, but
> unless I missed something, it does not validate referenced Templates or
> files from import or parse directives. Any thoughts. Would it be difficult
> to implement?

Yes, if you mean a template figuring out if it would be structurally
different based on #parse() or #include(), because you can

#parse( $foo )

Now what should it do?  Render $foo and figure it out?

It certainly is *possible* (everything is possible.)

However, how often in a production system will you change templates?

That said, if very, very rare, why not just use the DataSource loader,
and have your app treat the template as data, and check?

Or even better, implement your own cache... Maybe we should provide a 

public Template getTemplate( Reader )

method in o.a.v.app.Velocity to allow you to do this, to do your own
resource management at app level for those so inclined? 

(which I think will be a small minority...)

It was a long day today, so I am basically babbling, but I think there
are quite a few alternatives to consider.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."