My App uses MySQL DB on the server where data changes every few minutes at the backend. I use
I am new to streamlit
st.experimental_connection(‘mysql’, type=‘sql’,ttl=300) to connect to the db and the app is used to present the data. Added the ttl = 300 expecting a refresh. However, the data is not refreshed on the app unless I reboot the app. Any idea where I am going wrong?
While I’m not so familiar with experimental_connection, I believe the ttl parameter stores the results of your queries in the cache for the specified amount of time. This means that in your case, once queried, the results are stored in the cache for 300 seconds (5 minutes). For any of the same queries you make, results are pulled from the cache instead of querying the database again, which is why you may be seeing the not being refreshed.
I believe setting the ttl parameter to a much lower value can be the solution. I will try an SQL connection and know if it works. Maybe one of the devs can give a specific answer.
You can set ttl=0 to disable caching of the resource. Also, if you want to refresh data, you can also add st.experimental_rerun, which reruns the script so that data can be updated again.
To be clear, the data won’t automatically be updated even if the cache is expired, unless something triggers the app to rerun. For example, if you add a “refresh” button and hit that after the cache expires, the query should be redone and show the new data. Does that work for you?
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.