How to clear cache thoroughly?

my app is: https://ntch-recommender.streamlit.app/
repo: Github - streamlit/app.py

I keep getting “Streamlit server consistently failed status checks, Please fix the errors, push an update to the git repo, or reboot the app.”

My application allows users to choose a ML model out of 4 models trained on different date. Upon choosing the model, the app will load the weights and re-construct the model, and then the app could generate recommendations.

The app works fine on the default model and the first user choice model. But when the user choose a third model, the app will crash. I guess I reach the memory limit loading more than 2 models even I use st.cache_resource. Neither setting the max_entries to 1 nor using st.cache_resource.clear() help.

How can I resolve this issue?

I figure a way out to solve my problem.

So, I use st.session_state to check if the user has selected a different model. If yes, then use st.cache_resource.clear() to clear previously loaded ML model, since the create model function is the only function decorated by st.cache_resource.

if 'd' not in st.session_state:
    st.session_state['d'] = d

if st.session_state['d'] != d:
    st.cache_resource.clear()
    calculate_similarity.clear()
    st.session_state['d'] = d

Thanks for also sharing your solution with the community, this will be helpful for those who encounter a similar issue.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.