Python Forum
How do I get the info for a cached property?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I get the info for a cached property?
#1
Say I have the following class with a property that has an expensive operation:

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?
Reply


Messages In This Thread
How do I get the info for a cached property? - by arnavb - Sep-01-2018, 11:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What is all the info in the info window in Idle? Pedroski55 3 740 Jul-08-2023, 11:26 AM
Last Post: DeaD_EyE
  Subclass initialized property used in parent class method. Is it bad coding practice? saavedra29 5 1,889 Feb-07-2022, 07:29 PM
Last Post: saavedra29
  ABC Module and @property decorator, Pythonic Way? muzikman 21 5,867 Aug-18-2021, 06:08 PM
Last Post: muzikman
  @property vs __set__ / __get__ and __setattr__ / __getattr__ okhajut 1 3,397 Jun-15-2021, 03:48 PM
Last Post: snippsat
  Can property getters and setters have additional arguments? pjfarley3 2 3,080 Oct-30-2020, 12:17 AM
Last Post: pjfarley3
  Property price calculation oli_action 4 3,208 Jul-15-2020, 04:27 PM
Last Post: sridhar
  Use of @property decorator ruy 16 6,723 Jun-09-2020, 05:29 PM
Last Post: buran
  Problem adding keys/values to dictionary where keynames = "property" and "value" jasonashaw 1 2,079 Dec-17-2019, 08:00 PM
Last Post: jasonashaw
  strange class property KaliLinux 2 2,391 Nov-25-2019, 04:32 PM
Last Post: KaliLinux
  print all method and property of list object engmoh 4 2,901 Oct-26-2019, 05:33 PM
Last Post: engmoh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020