What does 'persist' in st.cache mean?

So the docs say that the format for cache is st.cache(func=None, persist=False, allow_output_mutation=False, show_spinner=True, suppress_st_warning=False, hash_funcs=None, max_entries=None, ttl=None)

I wonder what persist really means here. Does that mean we can save cache on users’s local storage rather than using our server’s memory/disk?

Another thing: if the cache is, by default, stored in the memory of the server and destroyed once the session ends, how does streamlit become aware of the familiarity with the function the next time the same arguments are passed now that the cache is gone?

Hi @mansidak :wave:

st.cache was deprecated in version 1.18.0. Use st.cache_data or st.cache_resource instead.

The docstrings for the new commands explain what the persist param means:

  • persist (str or boolean or None): Optional location to persist cached data to. Passing “disk” (or True) will persist the cached data to the local disk. None (or False) will disable persistence. The default is None.

Does that mean we can save cache on users’s local storage rather than using our server’s memory/disk?

It means that when passing "disk" or True to persist, Streamlit will persist the cached data to the local disk where the application is deployed. i.e. the remote server, not the users’ local disk.

Another thing: if the cache is, by default, stored in the memory of the server and destroyed once the session ends, how does streamlit become aware of the familiarity with the function the next time the same arguments are passed now that the cache is gone?

The caching mechanism is explained in detail in the new caching docs:

@snehankekre Gotchu. So when you say

Streamlit will persist the cached data to the local disk where the application is deployed.

Does that mean it’s stored on disk volume or the RAM memory?

The former. The cache is written to disk on the filesystem where the app is deployed.

@snehankekre Gotchu. The reason I asked this is because we recently started caching a big function and the RAM has been going up exponentially since then. Everything else has stayed the same so we suspected that cache might be causing increase in RAM.

@snehankekre Do you know if the stores cache persists after the process is killed? I understand that it is saved in disk storage instead of memory, but does this mean that the cache will still be accessible the next time the app is run? If so, where can I find the stores cache’s location on my machine?

@snehankekre to similar question, to persist just indefintely persist data to disk? is there way to have janitor process or something that ensures data gets deleted after certain amount of time or only so much memory stored on disk (namely just worry about using persist and data staying on disk of server indefinitely)?