Clearing Cache

Dear friends,

I am currently writing a web-application and need to “refresh the page” by clearing the cache. So the user should be able to refresh the page. For this reason I created a button with the following statement in it st.legacy_caching.caching.clear_cache(). However, even I have the most updated version (1.12.0) I get the following error “module ‘streamlit’ has no attribute 'legacy_caching’”

my code looks like this

@st.cache(allow_output_mutation=True, suppress_st_warning=True)
def load_General():
    engine = sa.create_engine("mssql+pyodbc:///?odbc_connect={}".format(params))
    return General_raw, General_cleansed

def load_Role():
    engine = sa.create_engine("mssql+pyodbc:///?odbc_connect={}".format(params))
    return Role_raw,Role_cleansed

With the following line(s) I try to clean the cache in order to be able to get the latest data from the DB

def clear_cache():

st.sidebar.button("Refresh Program",on_click=clear_cache)

Any Idea what could help me here?

Hi @Isaak_Saba :wave:

The .clear_cache() method for st.cache isn’t part of the public API. We frequently refactor parts of Streamlit’s internals to fix bugs, improve performance, and add new features; we’re not able to maintain backwards compatibility for non-public APIs.

I know this can be frustrating! There are a couple of options here: the quickest fix is to use st.runtime.legacy_caching.clear_cache(), as legacy_caching is now part of a streamlit.runtime package. The more durable option is to use the newer cache primitives @st.experimental_singleton and @st.experimental_memo and their respective .clear() commands.

You may also be interested in contributing to the discussion in: We want to deprecate st.cache! …and need your input ❤️


Thanks so much :), really saved my life

I decided to go with st.experimental_memo which works smooth

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.