[Zope-CMF] Re: RFC: browser views and memoization
whit
whit at burningman.com
Tue Jan 17 18:30:25 EST 2006
hi yuppie!
good to know about decorators as class vars and I guess that makes sense
since they are created at import rather than instantiation.
> def memoize(meth):
> def memoized_meth(self, *args):
> if not hasattr(self, '_memo'):
> self._memo = {}
> sig = (meth, args)
> if sig not in self._memo:
> self._memo[sig] = meth(self, *args)
> return self._memo[sig]
> return memoized_meth
>
> _memo is now an instance attribute and should be garbage collected with
> the view instance. Does that look sane?
>
> I don't care about kwargs and non-hashable args at the moment. I just
> want to find out if using a memoize decorator is the right approach for
> resolving the problem described in my initial mail.
I think this looks cleaner and more effective than the alternatives.
-w
More information about the Zope-CMF
mailing list