Hi!
The skin scripts for complex forms in CMF like folder_contents are
currently big monolithic blocks of code. All the values needed in the
template are computed in a predefined order that makes sure expensive
tasks like querying the catalog or listing folder contents are performed
only once (per request).
Trying to convert this into a browser view and to split the code in
several methods I stumbled other the following issue:
If globally needed values are returned by their own method they have to
be computed again and again, although during the short live of a view
class they can be considered static.
One option would be to pre-compute those values in the __call__ method
and to store them in the view object. An other option is to cache the
results.
I ended up using this method as decorator for most methods:
def memoize(func):
memo = {}
def memoized_func(*args):
if args not in memo:
memo[args] = func(*args)
return memo[args]
return memoized_func
Are there better ways to resolve this?
Will those memo dicts be removed together with the view object or does
this create a potential memory leak? (I'm not very familiar with
decorators.)
Cheers,
Yuppie
_______________________________________________
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