Caching per user


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?

def cached_results_for_you(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.

1 Like

Thanks Caroline!

So, if the method does not need to return a value, would returning 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 =

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

1 Like