Streamlit Cache

Learn to make applications more efficient.

Improve application efficiency

Streamlit provides a way to make our applications more efficient with the @st.cache decorator. This enables our application to use stored values in any computation required. The application doesn’t need to fetch data afresh each time the computation runs unless one of three following things happens:

  • A function’s input parameters change.
  • A function’s body changes.
  • An inner function changes.

To use it, we call the decorator just before defining the function. The code below demonstrates the benefits of using the @st.cache decorator:

Execute the example

Let’s run the application below to see the benefit of using @st.cache to improve efficiency:

Get hands-on with 1200+ tech skills courses.