Overview

Streamlit 1.15, released on September 20, 2022, introduces st.cache_data for finer and more predictable caching.

Main Features

st.cache_data

st.cache_data replaces st.cache for caching serializable data, with more predictable behavior and no side effects.

python
import streamlit as st
import pandas as pd

@st.cache_data
def load_data(url: str) -> pd.DataFrame:
    return pd.read_csv(url)

df = load_data('https://example.com/data.csv')
st.dataframe(df)

st.cache_resource

st.cache_resource is designed for non-serializable resources like database connections and ML models.

python
import streamlit as st

@st.cache_resource
def get_connection():
    # Connection shared across reruns
    import sqlite3
    return sqlite3.connect('app.db')

conn = get_connection()
st.write('Connection established')

Sources