From d9a1bc3748cd2a0c1910a77da40ae83eaee0c1d4 Mon Sep 17 00:00:00 2001 From: Julien Muchembled <jm@nexedi.com> Date: Fri, 16 Oct 2009 11:43:32 +0000 Subject: [PATCH] Really fix caching_class_method_decorator and comment it git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29752 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/Cache.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/product/ERP5Type/Cache.py b/product/ERP5Type/Cache.py index 115ebf3e9b..7f0def74d8 100644 --- a/product/ERP5Type/Cache.py +++ b/product/ERP5Type/Cache.py @@ -281,5 +281,12 @@ def generateCacheIdWithoutFirstArg(method_id, *args, **kwd): def caching_class_method_decorator(*args, **kw): kw.setdefault('cache_id_func', generateCacheIdWithoutFirstArg) def wrapped(method): - return lambda *a, **k: CachingMethod(method, *args, **kw)(*a, **k) + # The speed of returned function must be fast + # so we instanciate CachingMethod now. + caching_method = CachingMethod(method, *args, **kw) + # Here, we can't return caching_method directly because an instanciated + # class with a __call__ method does not behave exactly like a simple + # function: if the decorator is used to create a method, the instance on + # which the method is called would not be passed as first parameter. + return lambda *args, **kw: caching_method(*args, **kw) return wrapped -- 2.30.9