Data-driven apps sometimes require expensive queries / function calls, which one may want to cache for them to be fast the next time around.
I’m asking this because I noticed that one of the standard python approaches (just decorating the expensive function with
@functools.lru_cache) doesn’t work in panel - e.g. running the following “panel app” results in the “function executed” string being printed on every reload.
from functools import lru_cache @lru_cache(maxsize=1) def test(): print("function executed") return 1 test()
I know too little about the panel implementation to know why this is the case (are different requests handled in separate threads?), but it would be very useful if there was a similarly convenient way of caching function calls in a panel app.