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?
#2
Maybe not the best, but
from functools import lru_cache
 
class Example:

    @property
    def a_getter(self):
        return self._a_getter()

    @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())
would be interesting to see other suggestions
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: How do I get the info for a cached property? - by buran - Sep-02-2018, 09:32 AM

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,871 Aug-18-2021, 06:08 PM
Last Post: muzikman
  @property vs __set__ / __get__ and __setattr__ / __getattr__ okhajut 1 3,399 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