[Zope] DTMLFile question

tomas@fabula.de tomas@fabula.de
Wed, 14 Aug 2002 09:14:23 +0200


On Wed, Aug 14, 2002 at 12:13:55AM -0400, Jens Vagelpohl wrote:
> what is supposed to be "lazy" about re-instantiating those DTMLFiles every 
> single time you call that "render" method??? i don't get it. the only "lazy"
>  thing to do would be - as is the usual case - instantiate them once on 
> startup.

Hmmm, yeah. I was over-concise, lazy, so-to-speak. Of course, in the real
thing, I'd cache the instantiation, like so:

  |class CMSResource( Traversable.Traversable, ...)
  |    "Yadda, yadda"
  |
  |    ...
  |
  |    def render(name, args):
  |      if self._templ.has_key(name):
  |        d = self._templ[name]
  |      else: # make new one
  |        d = DTMLFile("dtml/CMSResource/" + name)
  |        self._templ[name] = d
  |
  |      return <<call d with appropriate arguments>>

> 
> if you don't have some really good reason why instantiating them once at 
> class level is horribly bad then you should just stick with that.

But you are right, I'd still get a handful of instances of DTMLFile per
CMSResource instance. It's not as bad as you thought, but still, if I've
got many CMSResource instances...

What I'm looking then is a way to `augment' the class with DTML methods
on an `as needed' basis.

Still, the difficult part would be  <<call d with appropriate arguments>>
since it seems to rely heavyly on being called as a class method (the Zope
magic doesn't seem to work as it should when I call it as an ordinary
function).

Thanks a lot for the insight!
-- tomas