Inspired by this caching recipe and to continue with the previous post, I think it will be more readable, clean and reusable if we use a decorator to cache methods inside a tool:
The cachedmethod decorator would be as follow (The code is not tested):
Decorators make magic easy.
class myTool(...):
@cachedmethod
def getMyDataFromDB(*args, **kw):
data = fetch_mydata_from_db()
return data
The cachedmethod decorator would be as follow (The code is not tested):