[Zope-CMF] [dev] refactoring listFilteredActionsFor: 2 questions

Chris McDonough chrism at plope.com
Thu Nov 20 17:34:32 EST 2003


On Thu, 2003-11-20 at 12:23, Yuppie wrote:
> So I experimented with storing the ExpressionContext in _v_skindata, 
> based on the assumption that
> i)  _v_skindata is always available in CMF
> ii) _v_skindata is new for each request
> 
> It seems to work pretty well, but I'm not sure that's a sane approach 
> and there might be better solutions. Any ideas?

You might be able to use the REQUEST._hold method to invoke a callback
when the request dies to invalidate a _v_ cache on the actions tool
itself (instead of depending on the skins implementation to do it for
you...):

Here's a helper class for calling a method when an object is deleted:

class deletion_callback:
    def __init__(self, callback):
        self.callback = callback

    def __del__(self):
        callback()

.. then, change createExprContext to accept "cachecontext" as
   an optional parameter (typically the argument to this would be
   the  actions tool itself passing itself in as cachecontext)
   and at the top of createExprContent:

    key = ( id(folder), id(portal), id(object) )
    _marker = []
    cache = None
    if cachecontext:
        cache = getattr(cachecontext, '_v_expression_cache', None)
        if not isinstance(cache, types.DictionaryType):
            cache = cachecontext._v_expression_cache = {}
        ec = cache.get(key, _marker)
    else:
        ec = _marker
    if ec is _marker:
       ... do all the stuff it does now plus...
       ec = getEngine().getContext(data)
       if cache:
           cache[key] = ec
           req = getattr(folder, 'REQUEST')
           if not hasattr(req, '_expression_cache_held'):
               req._hold(deletion_callback(cache.clear))
               req._expression_cache_held = 1
     return ec

... or something like that ... ;-)  I think the skins tool does
something similar to cache lookups within the context of a single
request.  You should probably sanity check my suggestion against what it
does (because it works ;-)

> b) call methods with ExpressionContext as argument
> ==================================================

How would this speed anything up when repeatedly invoking
listFilteredActionsFor during a single request?  Or are you suggesting
changing all of the places where listFilteredActionsFor is now called?

- C





More information about the Zope-CMF mailing list