Function decorator that caches function results
Sam Pointon
free.condiments at gmail.com
Sat Oct 8 11:02:18 EDT 2005
What about not storing args at all? Something like this:
def cache_function(func, args_list):
cache = {}
def cached_result(*args, **kwargs):
kwargs.update(dict(zip(args_list, args)))
if kwargs in cache:
return cache[kwargs]
result = func(**kwargs)
cache[kwargs] = result
return result
return cached_result
args_list is a list of all the argument names, so that they can be
converted into keyword arguments.
More information about the Python-list
mailing list