Black Lives Matter. Please consider donating to Black Girls Code today.

Caching with button callbacks

When setting up a callback that is fired with a button using n_clicks, caching is impossible as there is always different input data to the callback.
Is there any way to fire a button callback without the n_clicks property that changes, or even better, ignore specific attributes for caching?
Thanks, mark9064

You can cache another function inside callback. Something like this:

@cache.memoize(timeout=300) 
def get_pd():
     return data

@app.callback(...)
def button_pressed(...):
     data = get_pd()

Hope, this helps.

2 Likes

Perfect - thanks :heart: