Caching stores the result of slow work so later calls with the same parameters can reuse it instead of repeating the work. In a Streamlit dashboard, this keeps data loading from slowing every interaction or page refresh. section 6.2.3 section 6.2
A practical caching flow looks like this:
- Identify a slow function, such as one that reads a CSV file into a pandas DataFrame. section 6.2.3
- Add the @st.cache_data decorator above the function; the decorator adds caching without rewriting its logic. section 6.2.3
- Let Streamlit reuse the stored result on subsequent calls, app reruns, and page refreshes. section 6.2.3
- Set a time-to-live or a user-friendly loading message when freshness and feedback matter. section 6.2.3
Caching dashboard data
Decorate a data-loading function so the CSV is read once and reused: @st.cache_data(ttl="1d", show_spinner="Reading sales data...") followed by load_data returning pd.read_csv(SALES_DATA_PATH). The first load can show progress; later loads should appear instantly. section 6.2.3
@st.cache_data
def load_data():
return pd.read_csv(SALES_DATA_PATH)
Inspect the minimal decorator and data-loading pattern for applying caching to a Streamlit function. section 6.2.3





































