diff options
| author | Olivier Laurent <olt@tinyerp.com> | 2008-12-15 17:25:07 +0100 |
|---|---|---|
| committer | Olivier Laurent <olt@tinyerp.com> | 2008-12-15 17:25:07 +0100 |
| commit | 8deaf883c75ff71e3bee3a871df89f12dafb87b2 (patch) | |
| tree | e26af93546384b88297639526063fbdf391632f7 /bin/tools/misc.py | |
| parent | 9f9f2ff78e08cd826f09f3f7dab0a80723112bbf (diff) | |
| parent | be2a0a76bbd95ce83cc68a10ce25e5b60279a0e6 (diff) | |
merge
bzr revid: olt@tinyerp.com-20081215162507-8oox01yssbfbbetf
Diffstat (limited to 'bin/tools/misc.py')
| -rw-r--r-- | bin/tools/misc.py | 16 |
1 files 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 |
