Let’s say you have an app setup to cache some data. But you need to clear that data, re-compute, and update a graph if a “Submit” button is clicked. What is the proper code for it? cache.clear()
doesn’t seem to clear the cache, so I think I might be doing it wrong. This is an example code I have that I’m thinking about:
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
cache = Cache(app.server, config={
#'CACHE_TYPE': 'redis',
# Note that filesystem cache doesn't work on systems with ephemeral
# filesystems like Heroku.
'CACHE_TYPE': 'filesystem',
'CACHE_DIR': 'cache',
# should be equal to maximum number of users on the app at a single time
# higher numbers will store more data in the filesystem / redis cache
'CACHE_THRESHOLD': 200
})
def get_data(session_id, value):
@cache.memoize()
def serialize(session_id, value):
# do my expensive computations
return pd.read_json(serialize(session_id, value))
@callback for my button
def my_button():
cache.clear()