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

_______________________________________________
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to