Python 如何清除特定Streamlight缓存?
我使用一些缓存运行streamlight脚本 当我使用以下代码时,它会清除所有缓存:Python 如何清除特定Streamlight缓存?,python,caching,streamlit,Python,Caching,Streamlit,我使用一些缓存运行streamlight脚本 当我使用以下代码时,它会清除所有缓存: from streamlit import caching caching.clear_cache() 我只想清除一个特定的缓存。我如何才能做到这一点?这目前(很难)做到 这是一个可选解决方案,可应用于某些情况: 您可以使用allow\u output\u mutation选项: import streamlit as st @st.cache(allow_output_mutation=True) de
from streamlit import caching
caching.clear_cache()
我只想清除一个特定的缓存。我如何才能做到这一点?这目前(很难)做到
这是一个可选解决方案,可应用于某些情况:
您可以使用allow\u output\u mutation
选项:
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()
我将返回的缓存对象写为list,但您也可以使用其他对象类型(然后必须替换特定于list的clear
方法)
有关更多信息,请查看,这目前(很难)实现
这是一个可选解决方案,可应用于某些情况:
您可以使用allow\u output\u mutation
选项:
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()
我将返回的缓存对象写为list,但您也可以使用其他对象类型(然后必须替换特定于list的clear
方法)
欲了解更多信息,请访问