From 7b6ed023c0cb54096a7110e923566b77ba7eb39b Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 15 Dec 2008 12:58:01 +0100 Subject: [PATCH] [FIX] fix with cache key generation lp bug: https://launchpad.net/bugs/307734 fixed bzr revid: christophe@cobalt-20081215115801-3x1ycw64uak5yvdk --- bin/tools/misc.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bin/tools/misc.py b/bin/tools/misc.py index 8d2a821f5d7..fbdaf44c55b 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -531,12 +531,14 @@ def is_hashable(h): except TypeError: return False -# -# Use it as a decorator of the function you plan to cache -# Timeout: 0 = no timeout, otherwise in seconds -# class cache(object): + """ + Use it as a decorator of the function you plan to cache + Timeout: 0 = no timeout, otherwise in seconds + """ + def __init__(self, timeout=10000, skiparg=2, multi=None): + assert skiparg >= 2 # at least self and cr self.timeout = timeout self.skiparg = skiparg self.multi = multi @@ -553,9 +555,9 @@ class cache(object): del self.cache[kwargs['clear_keys']] return True - # Update named arguments with positional argument values + # Update named arguments with positional argument values (without self and cr) kwargs2 = kwargs.copy() - kwargs2.update(dict(zip(arg_names, args))) + kwargs2.update(dict(zip(arg_names, args[self.skiparg-2:]))) for k in kwargs2: if isinstance(kwargs2[k], (list, dict, set)): kwargs2[k] = tuple(kwargs2[k]) @@ -577,7 +579,7 @@ class cache(object): # Work out new value, cache it and return it # FIXME Should copy() this value to avoid futur modifications of the cache ? # FIXME What about exceptions ? - result = fn(self2,cr,*args, **kwargs) + result = fn(self2, cr, *args, **kwargs) self.cache[key] = (result, time.time()) return result