Don't use kwargs as part of the memoize key

This should be fixed later (if at all possible). Also see discussion at
http://stackoverflow.com/questions/6407993/how-to-memoize-kwargs

Refs #205.
This commit is contained in:
Kim Silkebækken 2013-02-12 10:45:24 +01:00
parent d638f1d6ea
commit e89e083fee
1 changed files with 6 additions and 3 deletions

View File

@ -16,10 +16,13 @@ class memoize(object):
@wraps(func)
def decorated_function(*args, **kwargs):
if self.additional_key:
key = (func.__name__, args, tuple(kwargs.items()), self.additional_key(*args, **kwargs))
key = (func.__name__, args, self.additional_key(*args, **kwargs))
else:
key = (func.__name__, args, tuple(kwargs.items()))
key = (func.__name__, args)
try:
cached = self._cache.get(key, None)
except TypeError:
return func(*args, **kwargs)
if cached is None or time.time() - cached['time'] > self.timeout:
cached = self._cache[key] = {
'result': func(*args, **kwargs),