Open bringtree opened 6 years ago
cache 保存函数结果
class Cache: def __init__(self, func): self.func = func self.data = {} def __call__(self, *args, **kwargs): func = self.func data = self.data key = f'{func.__name__}-{str(args)}-{str(kwargs)}' if key in data: result = data.get(key) else: result = func(*args, **kwargs) data[key] = result return result
cache 保存函数结果