Caching data across interactions

Hi streamlit, please help correct me if I’m wrong. I have 50M+ json file to load and play with the data inside. The data itself don’t change, so I try to @st.cache it. The code is like following,

@st.cache
def load_data(filename): 
    data = json.load(open(filename))
    do_some_data_cleaning_job_in_memory..
    return data

data=load_data("batch101.json")       # the 50M+ file, and type(data)==dict
category=st.sidebar.radio("Category:", list(data.keys()))
id=st.sidebar.slide("Data_id:", min_val=0, max_val=len(data[category])-1)

st.write(data[category][id])

But each time I interact with the widget, the page will show “Running load_data” and page gets gray for about 5 seconds. It looks like the caching is not working here. Am I doing something wrong? Thanks for any advice.

ah, I found this:

@st.cache(allow_output_mutation=True)

will disable hash checking, now that I am sure the returned data will not change.

Thanks for the awesome job, Streamlit!

2 Likes