Cache issue when deployed on Streamlit Cloud

I have a cache issue. In my app I allow the user to upload a file and can do a bunch of things. When the app is deployed to Streamlit cloud what I notice is the file uploaded by say user #1 remains in the cache and when user #2 uploads their document it has no effect and only user #1’s document is used. I want to clear the cache programtically before the uploaded file is processed. How can I accomplish this?

def clear_submit():
    st.session_state["submit"] = False

placeholder_upload = st.empty()
with placeholder_upload.container():
    uploaded_file = st.file_uploader(
        "Upload a pdf, docx, or txt file.",
        type=["pdf", "docx", "txt", "csv"],
        help="No scanned documents please!",
index = None
doc = None
if uploaded_file is not None:
        doc = parse_pdf(uploaded_file)
        doc = parse_docx(uploaded_file)
        doc = parse_txt(uploaded_file)
        doc = parse_csv(uploaded_file)
        st.session_state["api_key_configured"] = True
        raise ValueError("File type not supported!")

Hi @AI-Dad,

Let’s take a look at this basic Python function:

def foo(bar):
    return data

You can clear all cached entries for this function as follows:

You can also clear values from all in-memory or on-disk cached functions, as follows:

I’m not able to check whether the above code snippet works in your code as I don’t have access to the full code. Please let me know if it works or not. If not, please send us the full code and we can investigate further :slight_smile:

For more information about our new caching primitives, please see this document:

Best wishes,


I cannot reproduce the issue with my own implementations of parse_csv, parse_pdf and parse_txt. Maybe your implementations are different and that is where the issue lies.

1 Like

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