I have a problem understanding how to apply the @lru_cache
decorator properly. I have a dictionary attribute
that computes values by calling another function on a list of values. I want to cache any access to attribute
. Is there any way to declare the lru_cache invalid whenever there is a write to some_list
? So far, the code is as follows:
@property
@lru_cache(maxsize=None)
def attribute(self):
attribute = {}
for k in self.some_dict:
attribute[k] = self.complex_computation(self.some_list)
return attribute