Summary
I’m trying to figure out what’s the best way to separate and keep the cache per-user.
Would the following code the expected way, or any better ways?
@st.cache_data
def cached_results_for_you(email = st.experimental_user.email):
...
I’m trying to figure out what’s the best way to separate and keep the cache per-user.
Would the following code the expected way, or any better ways?
@st.cache_data
def cached_results_for_you(email = st.experimental_user.email):
...
As long as cached_results_for_you()
is returning data, that seems like it should work. Note that st.experimental_user
works on apps deployed with Streamlit Community Cloud only.
Thanks Caroline!
So, if the method does not need to return a value, would returning st.experimental_user.email
make sure it would run once per user?
My intended use case is that I’m generating large files that needed to be cleared when there’s a new code deployed. It takes long to generate them, so don’t want it to run every time — generate the files only when they are cleared and missing. (the code path is idempotent and is safe to run at any random time, it’s just slow and redundant)
def run_once(email = st.experimental_user.email):
clear_temp_files_from_previous_run()
return st.experimental_user.email
Whether the function runs again depends on whether the function has been called before with the same value for the email
parameter, so yes, this seems like it would accomplish what you’re looking for
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
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.
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.
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.
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.