Little update…
Thanks for the feedback everyone! Our main takeaway from here and other talks with users was:
- Splitting caching into two separate decorators is the right way to go!
- The names
memo
andsingleton
are too difficult to understand for a lot of users.
So the solution we’re now leaning towards is:
- Rename
st.experimental_memo
tost.cache_data
. This command should be used to cache any data objects, e.g. pandas dataframes, numpy arrays, str/int/float, or lists and dicts containing such data objects. Example use cases are dataframe transformations, API queries, ML inference, etc. Behavior will stay the same as forst.experimental_memo
, i.e. you always get a fresh copy of the return object at every rerun. This is also the default command you should use in 90% of all cases. - Rename
st.experimental_singleton
tost.cache_resource
. This command should be used to cache any global resources that will be shared across all reruns and sessions, e.g. database connections or ML models. For example if you’re initializing a connection or loading an ML model from disk. We’re also working on a more specificst.connection
command, which will allow you to connect to databases in a single line of code and should abstract away caching and similar details (see our roadmap blog post). We’re also thinking if we can do something similar for initializing ML models (e.g. anst.model
– comment if you have ideas!). In the long run, we seest.cache_resource
as an advanced command that most users won’t need to touch. - Do a much better job in the docs to explain these two commands, what their differences are, and in which situation you should use what.
We are now implementing the new commands and a few other adjustments. We want to release them in December/January and will start the deprecation of st.cache
then. We’re doing the deprecation in a very very careful way! Specifically, we won’t remove st.cache
at least until 2.0 to prevent breakage and we’ll give a lot of guidance (both in the app and in the docs) on how to move over to the new commands. In most situations, it should just be a small name change and you’re good to go.
Happy to hear any feedback that y’all have!