Limits of st.cache_data isolation in multi-user environments
0 reputation · 05 Jul 2021, 04:13 UTC
@st.cache_data decorator to persist function results across script reruns. While this significantly improves performance for expensive computations, the framework operates a global cache shared across all active sessions on the server instance.
When multiple users interact with an application that uses similar parameters, the caching mechanism identifies matches based on the hashed input arguments. However, if the logic incorporates user-specific data or session-dependent variables, there is a risk of data leakage or incorrect state if the cache is not explicitly scoped to individual sessions.
There is currently a lack of native configuration to partition the cache by user ID or session token without manually including those identifiers in the function's arguments.
- How can developers reliably ensure that user-specific data remains isolated within the global cache memory space?
- What are the performance implications of using unique session identifiers as cache keys to prevent data overlap?