mmcnl
December 21, 2021, 11:39am
1
I have been fighting with the cache function of Streamlit literally for days, and still am not able to achieve what I want.
I want to achieve the following:
On page load, load a dataset and cache it, so that next time when you load the page the dataset is retrieved from the cache
Click on a button to update the dataset so that it is refreshed manually with the latest information
How do I achieve this? This simple use case seems almost impossible to achieve. Help?
Hi @mmcnl -
This forum post sounds like what you are trying to do:
Here is a cached function, at_time is the timestamp used to control caching.
@st.cache
def get_phrase_data(start_date, end_date, phrases=None, at_time=None,
**kwargs):
"""Wrapper for :func:`load_metadata_for_period` for Streamlit caching
start_date and end_date should be ISO format strings in UTC for date
"""
#print('get_phrase_data', phrases)
data = load_metadata_for_period(start_date, end_date, phrases=phrases,
**…
Ultimately, the cache function uses the function inputs to determine whether the data already exists in cache to be served. So you need to do something like pass a timestamp or other method of unique keys to your load data function, so that when you hit the button it passes a new value to your function.
Best,
Randy
system
Closed
December 21, 2022, 4:53pm
4
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.