I have a class somewhat like following:
from joblib import Memory
import time
def find_static_methods(cls):
# to be implemented
pass
class A:
def __init__(self, cache_path: str):
self._memory = Memory(cache_path, verbose=0)
self._methods = {}
for name, method in find_static_methods(A):
self._methods[name] = self._memory.cache(method)
def __getattribute__(self, item):
if item in self._methods:
return self._methods[item]
return super(A, self).__getattribute__(item)
@staticmethod
def method1(a: int, b: int):
time.sleep(3)
return a + b
I'm trying to memoize method1
using joblib.Memory
. But I don't know the cache_path
in advance. Please help me with the implementation of find_static_methods
here.