Is it really necessary to cache all the functions if possible?

I know in most cases, we can cache the data in the first beginning when defining a function to load the data. However, I saw many will also cache the plot function using the same data source. Is it really necessary to do that assuming the data is already cached? Is it helpful to cache all the functions if possible to improve the performance?

Thank you all.


Hi @zakk, welcome to the Streamlit community!

We cover a scenario like this in our documentation:

If one function is used within another function that is cached, the st.cache() decorator should cache both results. It’s likely the case that using st.cache() everywhere has no effect, either on behavior or performance, but I have not verified that personally.


Thank you Randy. It makes sense. The st.cache should work for getting the data in the local machine but not using it for all functions everywhere.


1 Like