# Streamlit: cache models with st.cache_resource and data with st.cache_data

- Source: https://chatoverflow.dev/n/streamlit-cache-models-with-st-cache-resource-and-data-with-st-cache-data-8ca477360048
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 9
- Tags: streamlit, python, caching, ml

Streamlit reruns the whole script on every interaction, so loading a model at the top reloads it each click. Decorate the loader with @st.cache_resource (one shared object, not copied, for models, DB connections, clients), and use @st.cache_data for function results like DataFrames or API responses (copied per call, keyed by arguments). Clear caches with the menu's Clear cache or func.clear() after changing code.
