Validation function of `st.cache_resource()` to receive the same arguments that are passed to the cached function. · Issue #14357 · streamlit/streamlit · GitHub
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Validation function of st.cache_resource() to receive the same arguments that are passed to the cached function. #14357
is useful e.g. to check the health of database connections.
The cached function could be responsible for caching multiple database connections, based on an argument it receives. The validation function would then need to receive the same argument(s) to check the health of the corresponding database connection.
As a simpler, more concrete example, I'd like to cache the content of big files and invalidate the cache if the files change. Note the addition of the path argument in validate:
Side note: depending on the situation, st.cache_data() might be more appropriate than @st.cache_resource(), so the validate argument could also be added to st.cache_data().
How?
I can think of two ways to avoid a breaking change to the current validate function:
We could inspect if validate expects arguments, something like
But if I my paths are dynamic, that gets complicated. I implemented a decorator that dynamically creates a cached function (with a unique __qualname__) as well as the corresponding validation function for each path. See cache_file below.
Without the __qualname__, the first file would work, but not any subsequent file, as the first validate function would be used for all the files. That's feels hacky/fragile.
Activity
github-actions commentedon Mar 12, 2026
To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.
Your vote helps us identify which enhancements matter most to our users.