Hey Community ,
When building Streamlit apps, it’s always a good idea to wrap inside an
@st.cache all expensive computations and slow data fetches. But as well as
st.cache works, in many cases we also recognize that it fails when encountering certain objects like Tensorflow sessions, SpaCy objects, Lock objects, and so on.
So over the past months we started slowly releasing several improvements to how
st.cache works. These improvements fall into 3 categories:
Improvements to the caching logic. For example, we now support caching custom classes out of the box, we have better support for tuples, etc.
Improvements to error messages and accompanying documentation.
A new keyword argument called
hash_funcswhich allows you to customize the behavior of
st.cachefor your specific use case. In particular, if you ever encountered an object that
hash_funcsnow allows you to fix that yourself!
You can find out more about all these changes in our docs:
We’re super excited to release all these changes, but also realize they’re all still very new, and full of rough edges! So we would love some help tracking down issues so we can solve them ASAP.
If you encounter any problems with the latest
st.cache updates, please post to this thread. Specifically whenever you see the warning “Cannot hash object of type _______” let us know the name of that object, and provide a short code snippet if possible.
Thank you for your help in making Streamlit better, and we also welcome any other feedback or ideas you have on caching!