Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to clear the cache with each run #870

Closed
ssimontacchi opened this issue Dec 19, 2019 · 10 comments
Closed

How to clear the cache with each run #870

ssimontacchi opened this issue Dec 19, 2019 · 10 comments
Labels
type:enhancement Requests for feature enhancements or new features

Comments

@ssimontacchi
Copy link

First off, Streamlit is awesome.

I am making an app where every time you push a button the state changes, but I would like to clear the cache the first time the script is run. So every time the page is refreshed, the cache is cleared.

Thanks for your help!

@arraydude
Copy link
Contributor

arraydude commented Dec 23, 2019

Hey @ssimontacchi , thanks for using Streamlit !

It seems that your needing is related with this issue

Let us know if this helps you

@ssimontacchi
Copy link
Author

Thanks! My issue is that wherever I seem to put it in my code, it clears the state every time a button is pressed or slider is moved. Do you know what I am doing wrong?

@arraydude
Copy link
Contributor

Do you have a minimal example with the problem ? so I can help you with

With cache you refer to this streamlit function ? https://streamlit.io/docs/api.html#streamlit.cache or are you referring to the current app state ? if so could be related to this

@ssimontacchi
Copy link
Author

ssimontacchi commented Dec 23, 2019

Sure, if I implement this code block it shows the conundrum. Again, I'm looking to keep the state and only clear it with a refresh of the page. I get the same issue if I wrap the button in a function. Thanks!

import streamlit as st
from streamlit import caching

caching.clear_cache()

@st.cache(allow_output_mutation=True)
def get_state():
  return []

state = get_state()
state.append(len(state))
st.write(state)
st.button('Rerun')

@nthmost nthmost closed this as completed Dec 24, 2019
@nthmost nthmost reopened this Dec 24, 2019
@ssimontacchi
Copy link
Author

Is there a way to count how many times the report has been run since the last time the cache was cleared?

@ssimontacchi
Copy link
Author

I just added a reset button... Good enough for me! :)

@ssimontacchi
Copy link
Author

The app's flow just isn't quite right without an autoreset. Any advice would be awesome!

@jrhone
Copy link
Contributor

jrhone commented Jan 21, 2020

Hey @ssimontacchi ,

You could use the unofficial SessionState to store your data. It gets reset on a page refresh.

https://discuss.streamlit.io/t/preserving-state-across-sidebar-pages/107/2?u=jonathan_rhone

https://gist.github.com/tvst/036da038ab3e999a64497f42de966a92

@starrabb1t
Copy link

Hi, how to clear the cache for a specific session?? Is there any hack to do it?

@jrhone jrhone added community type:enhancement Requests for feature enhancements or new features labels Apr 24, 2020
@arraydude
Copy link
Contributor

Hi, how to clear the cache for a specific session?? Is there any hack to do it?

Hi @starrabb1t , maybe this thread helps you, if not please open a new discussion here with your use-case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement Requests for feature enhancements or new features
Projects
None yet
Development

No branches or pull requests

6 participants