Our solutions include two new primitives: st.experimental_memo and st.experimental_singleton. They're conceptually simpler and much, much faster. In some of our internal tests on caching large dataframes, @st.experimental_memo has outperformed @st.cache by an order of magnitude. That's over 10X faster! 🚀
Let's take a look at the use-cases these two experimental APIs serve, and how they're a significant improvement over @st.cache.
Problem
@st.cache was serving the following use-cases:
Storing computation results given different kinds of inputs. In Computer Science literature, this is called memoization.
Initializing an object exactly once, and reusing that same instance on each rerun for the Streamlit server's lifetime. This is called the singleton pattern.
Storing global state to be shared and modified across multiple Streamlit sessions (and, since Streamlit is threaded, you need to pay special attention to thread-safety).
