[Product-Developers] plone.memoize question

Christian Klinger cklinger at novareto.de
Thu Nov 20 08:56:14 UTC 2008


Hello Plone Developers,

i need some help with a plone.memoize caching.

I try to cache a method on a browser view only if
the result of the methods aktive == '1'.

This is my implementation:

def _render_details_cachekey(method, self):
     keys = self.veryExpensiveOftenCalledMethod()
     if keys.get('aktiv') == '1':
         return (keys.get('user',), keys.get('aktiv'))
     else:
         DontCache

class DisplayViewView(BrowserView):
     """
     DisplayView browser view
     """
     implements(IDisplayViewView)

     def getMemberId(self):
         pm = getToolByName(self, 'portal_membership')
         user = pm.getAuthenticatedMember()
         return user.getId()

     def veryExpensiveOftenCalledMethod(self):
         return {'user': self.getMemberId(), 'aktiv':'1'}

     @ram.cache(_render_details_cachekey)
     def test(self):
         print "CALL TEST"
         return self.veryExpensiveOftenCalledMethod()


Does this work?
Do you see any problems with it?

Thanks for your help.

Christian





More information about the Product-Developers mailing list