9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-11-18 11:23:38 +01:00
qp2/scripts/utility/qp_decorator.py

18 lines
330 B
Python
Raw Normal View History

2019-01-25 11:39:31 +01:00
from functools import wraps
def cache(func):
"""
A decorator for lazy evaluation off true function
"""
saved = {}
@wraps(func)
def newfunc(*args):
if args in saved:
return saved[args]
result = func(*args)
saved[args] = result
return result
return newfunc