Button to clear cache and rerun

module ā€˜streamlit.cachingā€™ has no attribute ā€˜clear_cacheā€™
???

What version of Streamlit are you using?

0.89

@rcsmit Aside from the caching - this script cannot work technically. You are nesting buttons. Buttons trigger reruns. Clicking the first button creates the second button. So far so good. Clicking the second button will again trigger a rerun. This time the first button is NOT clicked. So there is no way you can get two consecutive buttons to evaluate to TRUE in one run - you can only click one button per run. Do not nest buttons. You could use a checkbox instead, its state is persisted across reruns. I hope this makes sense for you. If you have questions, please ask.

3 Likes

I also do not see the clear_cache method on streamlit 0.89. Has it moved or is it a bug?

I notice the button is also gone from the hamburger menu in the app (although hitting the c key still works).

Hi @Hayk_Martiros,

Welcome to the Streamlit community! :wave:

The clear_cache method has moved to streamlit.legacy_caching.clear_cache.

With the 0.89.0 release, we have updated the configurable hamburger menu options!

The hamburger menu is now divided into the main section (visible to everyone) and the developer section (visible to developers only).
The developer section is context-aware. It appears if the app is running on localhost or if it was deployed in Streamlit Cloud (and if the current user is the appā€™s developer)
Here is what it looks like: The hamburger menu is now divided into the main section (visible to everyone) and the developer section (visible to developers only).
Here is what it looks like:

In light of the context-aware visual redesign, youā€™ll see the Clear cache button when viewing the app as a developer.

Happy Streamlit-ing! :balloon:
Snehan

2 Likes

the clear cache button, sometimes is useful to end users.
canā€™t i show them in the "viewer experience?

3 Likes

It is at times useful for me to clear cache programatically. Please be sure not to remove that option and make it front end driven.

4 Likes

Indeed. I have a covid dashboard which loads lots of files. And sometimes I want to clear the cache if I am on another computer without being logged in; I set the end date on a secret date and the the clear cache function startsā€¦

And now I get
AttributeError: module 'streamlit' has no attribute 'legacy_caching'

3 Likes

I totally agree. I always looked at Streamlit as a simple option to ā€œappifyā€ a notebook and make it accessible to others. A core feature for that would be to cache the latest result and have an option to rerun everything at once (similar to what is possible with a notebook). I mimicked this behavior by using the clear_cache() function, but thatā€™s not possible anymore. How should I approach this use case? Why is it not supported? I honestly fail to understand what Streamlit is if such an obvious feature is not included as one of the core features and workarounds are being removed.

Perhaps Iā€™m approaching this use case in the wrong way, Iā€™d love to be educated.

2 Likes

I would also like to point out the importance of being able to clear cache through a button. Without it, my end users will come to me asking to do it, which eliminates the entire point of having an automated dashboard.

4 Likes

Thank you all for your honest feedback! Iā€™m relaying it to the Streamlit dev team :balloon:

1 Like

Can you share the current considerations about caching? Why is it the way it currently is? I want to understand how Streamlit should be used according to the developers.

3 Likes

I would also love to have some kind of workaround solution to allow users to reset the cache. Itā€™s definitely been an issue for some of the apps I work on.

Clear cache is pretty much essential to my Streamlit end-user experience, and having it the hamburger menu was really nice as it didnā€™t take up any real estate. I would prefer if it was back.

@kevinlinxc @fdubinski you can now achieve the same thing by using
caching.clear_memo_cache()
caching.clear_singleton_cache()
Source: here

To be clear, thereā€™s still no way to clear the cache with ā€œCā€ like before, or via the hamburger menu, correct?

Hi, I upgraded to the latest version, but Iā€™m not able to use caching.clear_singleton_cache()

AttributeError: module ā€˜streamlit.cachingā€™ has no attribute ā€˜clear_singleton_cacheā€™

Hi @kimsb2429, welcome to the community! :partying_face: :wave:

The command youā€™re looking for is st.experimental_singleton.clear(). Calling this command will clear all singleton caches.

If you want to clear the singleton cache of a specific function, say foo(), you can use foo.clear(), provided foo() is decorated with @st.experimental_singleton.

Best, :balloon:
Snehan

2 Likes

Thatā€™s correct. You can clear the cache with ā€œCā€ or via the hamburger menu only if you are viewing the app as a developer.