Can st.cache_data be used for storing user choices/preferences longer than a session_state (which if I understand correctly(?) resets when a tab refreshes?). Iāve had an experience on mobile browser (Firefox) where leaving the tab inactive has triggered a refresh in the browser app, which has then reset the session state. Using cache seems like a more āpermanentā solution, but Iām not quite sure how to go about making it work, if itās even possible. Any help appreciated
hey @mrkthmpsn!
So st.cache_data is not going to be particularly helpful there. Youāre right, session_state lives only āas long as the tab is open and connected to the Streamlit server.ā What it sounds like youāre looking for is a persistent state for your app! I have seen many different flavors of this, some people integrate google sheets, other folks use firestore, even others use sqlite. It all depends on what you want to store, but if youāre looking to store user choices in a more persistent way than session_state, youāll probably need to go in this direction
Ah, thanks!
A follow-up, not sure if this is a stupid question, but would I be right in thinking that in those implementations youād need to store some kind of user identifier? Would they need to login?
Yes thatās a good point. One way of doing this would be to ask users in the app (e.g. in an expander) if they want to save their place in the app, and then if they say yes ask for their username and store the current data inputs
Then, have another place in your app (like in the sidebar) that just says āwant to start this app from a stored input state?ā, have them enter their username, and pull the data using the username.
There are more complicated but also more secure options, like @brianmhessās cool new feature with oath and snowflake or streamlit-keycloak.
Hope that helps
For future reference of anyone finding this thread, Iāve turned to the experimental_query_params for a couple of my simpler use cases