简体   繁体   中英

how can I clear specific streamlit cache?

I run streamlit script with a few caches.

When I use the following code it clears all the caches:

from streamlit import caching

caching.clear_cache()

I would like to clear only a specific cache. How can I do this?

This isn't currently (easily) doable.

This is an optional solution that can be applied to some cases:

You can use the allow_output_mutation option:

import streamlit as st

@st.cache(allow_output_mutation=True)
def mutable_cache():
    return some_list

mutable_object = mutable_cache()

if st.button("Clear history cache"):
    mutable_object.clear()

I wrote the returned cached object as list but you can use other object types as well (then you have to replace the clear method which is specific to lists).

For more info please look on the answers I got in the streamlit community forum

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM