-
Notifications
You must be signed in to change notification settings - Fork 450
caching of methods updating instance variables #431
Copy link
Copy link
Closed
Description
I haven't found an elegant way to cache methods updating instance variables:
class Foo(object):
def __init__(self, args):
self.data = None
def compute(self, ...):
... # long computation
self.data = result
One can create a cached private method that is returning computed data, but in this point the caching mechanism is already complicating the code:
class Foo(object):
def __init__(self, args):
self.data = None
self.__compute__ = mem.cache(self.__compute__)
def compute(self, ...):
...
self.data = self.__compute__(...)
def __compute__(self, ...):
... # long computation
return result
Proposal: a possible solution could be a specification of altered instance variables in the decorator:
self.compute = mem.cache(self.compute, [self.data, ...])
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels