How to reset the cache after a fixed frequency?

Hi ,

I have user case where dashboard base data gets updated in every 1 hour. For good response time I have used cache before data loading function. How I can make cache clear after say 1 hour so that user will see the refreshed data on dashboard.

Thanks,
Manoj Kumar

Can any one help on this?

Thanks

Hi @manoj_kumar :wave:

@st.experimental_memo() has a ttl parameter that is used to specify the maximum number of seconds to keep an entry in the cache.

You can expire the cache entries after an hour by setting ttl to 3600, like so:

import streamlit as st

# Expire the cache every 1 hour.
_CACHE_EXPIRY = 1 * 60 * 60

@st.experimental_memo(ttl=_CACHE_EXPIRY)
def load_data():
    # Perform and cache expensive data loading
    # Cache expires after ttl
    return data

Does this help?

Best, :balloon:
Snehan

Thanks let me try this