Sep-01-2018, 11:13 PM
Say I have the following class with a property that has an expensive operation:
Is there a way for me to get this cache info with the property decorator as well?
from functools import lru_cache class Example: @property @lru_cache(maxsize=None) def a_getter(self): print('Doing an expensive operation!') expensive_result = 5 return expensive_result test = Example() for i in range(0, 1000): a_variable = test.a_getter print(test.a_getter.cache_info())As evident, this does not run with 3.6.1, with the traceback:
Error:Traceback (most recent call last):
File "python", line 16, in <module>
AttributeError: 'int' object has no attribute 'cache_info'
However, if I remove the property decorator, then the code works (I just have to switch to a function call for the getter).Is there a way for me to get this cache info with the property decorator as well?