Originally Posted by chaley
You have a custom (Python) template function? If so, then yes you can cache results. The reason: each function is compiled into its own persistent class. You can store stuff as class attributes, which will persist until the next time calibre restarts, you change the library, or are running the function in a separate job.
The approach is to check if the desired cache class attribute exists. If so, use it. If not then fetch and store it, then use it. Sample code:
Code:
x = getattr(self, 'foobar', None)
if x is None:
self.foobar = {'element': 'value'} # do what it takes to set foobar's value
# use self.foobar in whatever way you want
It is up to you to invalidate the attribute (the 'cache') when needed. Simply restarting calibre will do it.
|