簡體   English   中英

如何清除特定的流式緩存?

[英]how can I clear specific streamlit cache?

我運行帶有一些緩存的streamlit腳本。

當我使用以下代碼時,它會清除所有緩存:

from streamlit import caching

caching.clear_cache()

我只想清除特定的緩存。 我怎樣才能做到這一點?

這目前(很容易)不可行。

這是一個可選的解決方案,可以應用於某些情況:

您可以使用allow_output_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()

我將返回的緩存對象寫為列表,但您也可以使用其他對象類型(然后您必須替換特定於列表的clear方法)。

有關更多信息,請查看我在流媒體社區論壇中得到的答案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM