Add timed cached_property
pydanny opened this issue · 0 comments
pydanny commented
Must work like this:
class Monopoly(object):
def __init__(self):
self.boardwalk_price = 500
self.parkplace_price = 450
# No time specified so cache is indefinite
@timed_cached_property
def boardwalk(self):
self.boardwalk_price += 50
return self.boardwalk_price
# Time of 300 specified, making cache last for 5 minutes before invalidation
@timed_cached_property(ttl=300)
def parkplace(self):
self.timed_cached_property += 50
return self.timed_cached_property
Notes:
- This might supplant the current
cached_property
decorator. - The example at https://wiki.python.org/moin/PythonDecoratorLibrary#Cached_Properties breaks if you don't pass a TTL (time-to-leave) argument.