Choosing Between st.cache_data and st.cache_resource in Streamlit
Pick the right Streamlit cache decorator: st.cache_data for copy-safe data, st.cache_resource for shared connections and models.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Pick the right Streamlit cache decorator: st.cache_data for copy-safe data, st.cache_resource for shared connections and models.
Streamlit’s @st.cache_data memoizes heavy data functions by hashing arguments, reducing recomputation on reruns. This guide shows how to configure TTL, size limits, and avoid stale data with a concrete CSV‑loading example.
Streamlit's st.fragment decorator isolates UI sections so only that fragment re-runs on widget changes — cutting dashboard latency from seconds to milliseconds without replacing caching.
Learn how to preserve widget values and app logic across Streamlit script reruns using session_state, with initialization, binding, reading, and reset patterns.
Learn how @st.fragment limits reruns to UI-only changes while preserving @st.cache_data and @st.cache_resource, with a practical example and notes on limits.
Learn how to use Streamlit’s st.cache_data decorator to avoid re‑loading large datasets on every interaction, with a concrete CSV‑loading example, version notes, and cache‑staleness mitigation.
Session State Persistence After Server Restart in Streamlit Determine whether Streamlit session state can be reliably recovered after a server restart without external backup. Session state is stored in memory per browser session and is cleared on server restart, redeploy, or browser close, with no documented automatic recovery mechanism. Because persistence