【问题标题】:how can I clear specific streamlit cache?如何清除特定的流光缓存?
【发布时间】:2020-05-31 09:44:44
【问题描述】:

我运行带有一些缓存的 streamlit 脚本。

当我使用以下代码时,它会清除所有缓存:

from streamlit import caching

caching.clear_cache()

我只想清除特定的缓存。我该怎么做?

【问题讨论】:

    标签: python caching streamlit


    【解决方案1】:

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

    这是可应用于某些情况的可选解决方案:

    您可以使用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 方法)。

    更多信息请关注the answers I got in the streamlit community forum

    【讨论】:

      猜你喜欢
      • 2019-03-08
      • 2012-02-05
      • 1970-01-01
      • 2016-04-16
      • 2013-08-16
      • 2020-06-13
      • 2020-08-22
      • 2014-11-03
      • 1970-01-01
      相关资源
      最近更新 更多