gpg: fix method's caching

This commit is contained in:
Roman Zeyde
2018-04-16 12:38:28 +03:00
parent 61e516e200
commit bc691ae795
2 changed files with 19 additions and 2 deletions

View File

@@ -215,6 +215,24 @@ def memoize(func):
return wrapper
def memoize_method(method):
"""Simple caching decorator."""
cache = {}
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
"""Caching wrapper."""
key = (args, tuple(sorted(kwargs.items())))
if key in cache:
return cache[key]
else:
result = method(self, *args, **kwargs)
cache[key] = result
return result
return wrapper
@memoize
def which(cmd):
"""Return full path to specified command, or raise OSError if missing."""