Having a lot of trouble sharing same variables along all the opened sessions


I have my streamlit functions built in a class. This class has self attributes (variables), and they change really often, from 3 to 10 seconds approximately. These variables are data being received from a websocket server which as far as I understand, is being shared in all sessions because I’m using @st.cache_resource decorator.

Now the problem I have is that I cant get to share the same variables to all the sessions. For example, if now I enter the website and start using it, data will start coming in, but if another user comes in, it wont be able to access the self attributes that the other users session has. I would like that to happen and I dont know how.

Should I have self attributes stored in a json instead, and get this data from the json so that all users have the same data? I would have a separate script that updates this json file. Now, my concern would be, will streamlit know when the data in the json changes so that it updates what the users sees? Thanks!

Hey @Ivan_Schuster,

If I’m understanding the use case correctly, I think the best solution would be to use a database to store the values that you want all users of the app to be able to access. Check out our guides on connecting to data sources here

even if variables will be changing every 3-10 seconds? I’ll try that out. Thanks a lot!