using @st.cache(ttl=3600) for example correctly caches a function that requests an API but in an individual way for each user that uses my web application. My intention is to save unnecessary requests and therefore use a shared cache. Is there a way to do this? I mean, the application stores the cache from the first execution and then uses it for 60 minutes for the next executions regardless of the user that executes it?
Interesting, I wasnโt aware of that either, I also thought until now that st.cache_data was applied to each individual session. I donโt think that is clear from the documentation.
But you could just test that: insert debug code into the cached function and use it from different sessions?
Oh, I have confirmed it. The debug code being just code that downloads and parses files large enough that you cannot avoid noticing whether it runs or not. Toy example below, using the proverbial time.sleep as an expensive operation.
import time
import streamlit as st
@st.cache_data
def square(number):
time.sleep(5)
return number**2
def main():
number = st.number_input(label="Number to square", value=0)
number_squared = square(number)
st.write(f"Number squared: {number_squared}")
if __name__ == "__main__":
main()
I have no idea how this relates to the issue you were having. If you think the behavior of cache_data does not match the documentation, posting an example would help to have it fixed.
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.