mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Add salt.utils.memoize() to cache return output
I looked at several ways to do this and played with it a bit. This was the shortest and most concise. It seems like there might be some other places to do it, so I added it as a utility function.
This commit is contained in:
parent
4c26f60049
commit
025dcdaa6a
@ -712,3 +712,14 @@ def str_to_num(text):
|
||||
except ValueError:
|
||||
return text
|
||||
|
||||
def memoize(func):
|
||||
'''
|
||||
Memoize aka cache the return output of a function
|
||||
given a specific set of arguments
|
||||
'''
|
||||
cache = {}
|
||||
def _m(*args):
|
||||
if args not in cache:
|
||||
cache[args] = func(*args)
|
||||
return cache[args]
|
||||
return _m
|
||||
|
Loading…
Reference in New Issue
Block a user