st.cache_data stores the result of a slow function call. When the function is called again with the same parameters, Streamlit reuses the stored result instead of running the function again. This keeps data-heavy dashboards responsive across reruns and page refreshes. section 6.2.3
Use it as a decorator by placing @st.cache_data above a function such as load_data. Streamlit then caches the returned pandas dataframe. The first run may show a spinner; later calls can return the cached dataframe. section 6.2.3
@st.cache_data
def load_data():
return pd.read_csv(SALES_DATA_PATH)
A minimal pattern for caching data loaded from a CSV file. section 6.2.3
Adjust the cache for practical dashboard behavior:
- Set ttl="1d" to make the cached result valid for one day. section 6.2.3
- Set show_spinner to a message such as "Reading sales data..." while the function runs. section 6.2.3

