When a function has the @st.cache_data decorator, is the result cached for only that session or for all sessions as long as the app is running?
I ask because both the st.cache_data docs and the caching docs explicity mention that things cached via @st.cache_resource persist across reruns, sessions, and users. However, the docs do not explicitly mention how @st.cache_data acts. Is it cached only for that session?
Goal
Originally, I implemented the caching to return results more quickly and only wanted the caching to persist for that single session. If @st.cache_data persists for all sessions, is using st.session_state the best way to do this?
Context
My deployed app calculates how many ballroom points an individual has. The app reaches out to external websites to retreive the data for the calculations. A user must enter the name of a person they want to calculate points for. I currently have @st.cache_data decorating the calculation function, where the input is the individual’s name.
Issue
I am running into an issue where when the external website updates with new results, the new results sometimes do not appear in my calculator. I was able to resolve this by redeploying the app. I am wondering if this is because if someone has searched “John Smith” before, then John Smith has new results, my calculator is always using the cached results and therefore will never see the new results John Smith has.
The “persist … and users” was for cache_RESOURCE, not cache_DATA. I was specifically referring to this part in the caching doc, which seemed to imply that cache_DATA may be for things where you don’t want to cache globally:
st.cache_resource is the right command to cache “resources" that should be available globally across all users, sessions, and reruns. […]
It seems like cache_RESOURCE and cache_DATA effectively act the same way to the end user. Is that correct? They both cache things globally but perhaps work differently on the back end.
Sorry, I overlooked that and now I understand why you feel confused.
Yes, they both cache globally, I can confirm that. The main difference is that cache_resource stores the object as is while cache_data stores a serialized version of it. But regarding the issue you describe, they both behave the same.
Thank you! Is there a process to request an update to the documentation? I think that would help prevent others like me from running into the same confusion. Tried searching around but couldn’t find a process to request documentation changes.