blob: 1c92a4e8db55f210a1412140c94a6d15b2128920 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
"""
Caches the return value of a function -> Result, regardless of input params
"""
class cached():
"""
A decorator to make the function cache its return value, regardless of input
"""
def __init__(self, fun):
self.fun = fun
self.__name__ = fun.__name__
def __call__(self, *args):
if not hasattr(self, 'retval'):
self.retval = self.fun(*args).unwrap()
return self.retval
def _drop(self):
if hasattr(self, 'retval'):
del self.retval
|