iTranslated by AI
[Web] Checking the Streamlit update
Introduction
About 10 hours before writing this, I received an update email from the official Streamlit team.
I've been building a Mahjong score calculation app as a hobby, and since I deploy the application to Streamlit Cloud, I was interested and checked the contents.
Update Details
st.cache has been updated and split into st.cache_data and st.cache_resource.
-
st.cache_data
Caches data computations. For example, DataFrame transformations, NumPy array calculations, machine learning model inferences, etc.
It seems it was originally named st.experimental_memo.
Suggested use cases include:
- DataFrames loaded from CSV
- Transformation results of NumPy arrays
- Results of queries to APIs
and so on.
-
st.cache_resource
Caches the initialization of shared resources (global resources). For example, database connections or machine learning models.
It was originally named st.experimental_singleton and is intended for caching items that follow the Singleton pattern (a design pattern that ensures only one instance is created).
With st.cache_resource, these resources can be shared across all reruns and sessions of the application without copying or duplicating them.
Why st.cache was split
It is noted that st.cache was being used in places where optimization goals differed.
For example, in the case of 1, cached objects need to be safe from changes. In other words, there must be a guarantee that the same value is returned when the function is used. Therefore, st.cache constantly checks if the object has been modified.
However, in the case of 2, it is considered unnecessary to check every time. But since st.cache checks constantly, there was an issue where execution became slow.
It seems this update was implemented to solve this problem.
Updating the Application
Check for packages with updates.
pip list -o
I confirmed that there is an update for Streamlit as shown below:

Since there seem to be many updates this time, updating them one by one with pip install package -U is a bit of a task. Therefore, I will use pip-review for a bulk update.
pip-review --auto

Now the update is complete. I will update the requirements.txt.
pip freeze > requirements.txt
Once you call the decorators from the application and confirm there are no issues, you are all set.
Discussion