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.
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!
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 onlocalhost
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!
Snehan
the clear cache button, sometimes is useful to end users.
canāt i show them in the "viewer experience?
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.
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'
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.
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.
Thank you all for your honest feedback! Iām relaying it to the Streamlit dev team
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.
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!
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,
Snehan
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.