据我所知,functools@cache decorator将记录这些参数。
然而,对于类的实例方法,参数包括“self”。
这会对性能产生影响吗?
class Test:
def __init__(self):
self.cache = {}
def test(self, a, b):
result = self.cache.get((a,b))
if result is None:
result = a + b
self.cache[(a,b)] = result
return result
上述操作是否会比简单地用@functools修饰test()更糟糕。隐藏物